/***************************CREATION OF NEW TABLE

***************************/
FIRST OF ALL WE HAVE TO CREATE A TABLE
SQL> CREATE TABLE MCA
(SNO NUMBER,
NAME CHAR(20),
ROLLNO NUMBER,
DOB DATE,
COURSE CHAR(6),
S CHAR,
AGE NUMBER,
GRADE VARCHAR(3));
Table created.

NOW TO SEE THE STRUCTURE OF THE TABLE WE USE DESCRIBE COMMAND .

SQL> DESC MCA
Name
Null?
Type
------------------------------- -------- --------------------------SNO
NUMBER
NAME
CHAR(20)
ROLLNO
NUMBER
DOB
DATE
COURSE
CHAR(6)
S
CHAR(1)
AGE
NUMBER
GRADE
VARCHAR2(3)
---------------------------------------------------------------------------

NOW TO SEE THE ALL ROWS IN A TABLE FOLLOWING COMMAND IS USED.22.'M'. 1 row created. 1 row created.--------.'PRADEEP CHAHAR'.'6-MAR-85'.20.-------------------.NOW WE HAVE TO POPULATE TABLE WITH DATA . 1 row created.'RAKESH SINGHMAR'.'SIMRAN PANCHAL'.-----.'M'. SQL> INSERT INTO MCA VALUES(4.--------.'MCA'.'MCA'.'SAGAR PANCHAL'. SQL> SELECT * FROM MCA.'A+').----------------------------------------1 KULDEEP SAINI 12 21-OCT-86 MCA M 21 A 2 RAKESH SINGHMAR 22 23-DEC-83 MCA M 23 A+ 3 PRADEEP CHAHAR 20 15-JAN-85 MCA M 22 A 4 SIMRAN PANCHAL 11 04-APR-86 MCA F 21 A++ 5 SAGAR PANCHAL 17 06-MAR-85 MCA M 22 A+ -------------------------------------------------------------------------------------------------------------- .’KULDEEP SAINI'. SQL> INSERT INTO MCA VALUES(5.'A+'). 1 row created.'F'.'M'.17..'A++').'MCA'.'21-OCT-86'.12. SNO NAME ROLLNO DOB COURSE S AGE GRA --------.'MCA'.'A').21. SQL> INSERT INTO MCA VALUES(1.'23-DEC-8'. 1 row created. SQL> INSERT INTO MCA VALUES(3.22.'15-JAN-85'.'MCA'.'A').22.21.'4-APR-86'.'M'. SQL> INSERT INTO MCA VALUES(2.MEANS WE HAVE TO ENTER ROW WITH THE HELP OF INSERT … COMMAND.11.23.--------.

SNO NAME ROLLNO DOB COURSE S AGE GRA --------.--------.. FOR EXAMPLE WE CAN RENAME. NOW THERE IS NO TABLE WITH NAME MCA.-------------------.AS GIVEN BELOW. .--------. Table renamed. THE MCA TABLE AS CSE . SQL> RENAME MCA TO CSE. SQL> SELECT * FROM MCA. SELECT * FROM MCA * ERROR at line 1: ORA-00942: table or view does not exist BUT THE FOLLOWING COMMAND WILL RUN SUCCESSFULLY./*******************************RENAME COMMAND******** ************************/ RENAME COMMAND IS USED TO RENAME A EXISTING TABLE .--------. Table renamed.-----------------------------------------------------1 KULDEEP SAINI 12 21-OCT-86 MCA M 21 A 2 RAKESH SINGHMAR 22 23-DEC-83 MCA M 23 A+ 3 PRADEEP CHAHAR 20 15-JAN-85 MCA M 22 A 4 SIMRAN PANCHAL 11 04-APR-86 MCA F 21 A++ 5 SAGAR PANCHAL 17 06-MAR-85 MCA M 22 A+ --------------------------------------------------------------------------------------------------------------------------SQL> RENAME CSE TO MCA.-----. IF WE WRITE THE FOLLOWING COMMAND THEN IT WILL SHOW ERROR MESSAGE. SQL> SELECT * FROM CSE.

SQL> CREATE TABLE MCA1 (SNO NUMBER.--------------------------SNO NUMBER NAME CHAR(20) ROLLNO NOT NULL NUMBER DOB DATE COURSE CHAR(6) S CHAR(1) AGE NUMBER GRADE VARCHAR2(3) ---------------------------------------------------------------------ON OTHER HAND THERE IS A TRANSACTION TABLE. NOW FIRST OF ALL WE CREATE A MASTER TABLE.THE MASTER TABLE CONTAIN ONLY ONE RECORD FOR EVERY STUDENT. MARKS NUMBER(3)).-------. ATTRIBUTES WHICH ARE PERMANENT LIKE NAME . ARE STORED IN ONE TABLE CALLED MASTER TABLE.IT CAN HAVE MORE THAN ONE RECORD FOR EVERY STUDENT SQL> CREATE TABLE MCA1_MARKS (ROLL_NO NUMBER REFERENCES MCA1. SUBJECT VARCHAR(10).ROLLNO NUMBER PRIMARY KEY. 5 S CHAR.COURSE etc. 3 DOB DATE.DOB. 4 COURSE CHAR(6)./*****************************REFERENTIAL INTEGRITY*****************************/ REFERENTIAL INTEGRITY IS AN IMPORTANT CONSTRAINT OF TABLES. Table created. SQL> DESC MCA1 Name Null? Type ------------------------------. . 7 GRADE VARCHAR(3)). Table created. 2 NAME CHAR(20). 6 AGE NUMBER. EXAM_DATE DATE.

'RAKESH SINGHMAR'. MCA1 IS A MASTER TABLE. 1 row created.22.22. SQL> INSERT INTO MCA1 VALUES(5.23.'A++').SQL> DESC MCA1_MARKS.'MCA'. Name Null? Type ------------------------------.'M'. 1 row created. SQL> INSERT INTO MCA1 VALUES(2.'A+').21. 1 row created.'A').'MCA'. 1 row created.'M'.'M'.17. SQL> INSERT INTO MCA1 VALUES(4. 'MCA'.-------.'M'.'MCA'.21. SQL> INSERT INTO MCA1 VALUES(1. .'A+'). 1 row created.'SIMRAN PANCAHAL '.'21-OCT-86'.12.'A').'23-DEC-83'.'SAGAR PANCHAL'.20. SQL> INSERT INTO MCA1 VALUES(3.'MCA'.'6-MAR-85'. MCA1_MARKS IS TRANSACTION TABLE.22.11.'4-APR-86'.'PRADEEP CHAHAR'.'F'.'KULDEEP SAINI'.'15-JAN-85'.----------------------ROLL_NO NUMBER SUBJECT VARCHAR2(10) EXAM_DATE DATE MARKS NUMBER(3) NOW.

'DATA BASE'.--------.'VC++'. SQL> SELECT * FROM MCA1_MARKS. ROLL_NO SUBJECT EXAM_DATE MARKS --------.78). 1 row created.88). 1 row created.---------.-----. SQL> INSERT INTO MCA1_MARKS VALUES(17.'VB'.----------..-----------11 VB 13-DEC-07 88 11 DATA BASE 11-DEC-07 78 17 VC++ 1 0-DEC-07 81 ---------------------------------------------------------------------------- .--------.'10-DEC-2007'.--------.---------------------------------------------------------1 KULDEEP SAINI 12 21-OCT-86 MCA M 21 A 2 RAKESH SINGHMAR 22 23-DEC-83 MCA M 23 A+ 3 PRADEEP CHAHAR 20 15-JAN-85 MCA M 22 A 4 SIMRAN PANCHAL 11 04-APR-86 MCA F 21 A++ 5 SAGAR PANCHAL 17 06-MAR-85 MCA M 22 A+ ------------------------------------------------------------------------------------------------------------------------------SQL> INSERT INTO MCA1_MARKS VALUES(11. SQL> INSERT INTO MCA1_MARKS VALUES(11.'13-DEC-2007'. 1 row created.'11-DEC-2007'.--------.-----------------. SNO NAME ROLLNO DOB COURSE S AGE GRA --------.SQL>SELECT * FROM MCA1.-------------------.81).

'11-DEC-2007'. SQL> CREATE TABLE MCA1_MARKS1 (ROLLNO NUMBER REFERENCES MCA1 ON DELETE CASCADE SUBJECT VARCHAR(10). . EXAM_DATE DATE.88).WE CAN USE ON DELETE CASCADE AS GIVEN BELOW TO SOLVE THIS PROBLEM .'VB'.'DATA BASE'. 1 row created.'10-DEC-2007'. 1 row created. DELETE FROM MCA1 WHERE ROLLNO=11 * ERROR at line 1: ORA-02292: integrity constraint (SCOTT. SO NOW WE CREATE ANOTHER TRANSACTION TABLE NAMED MCA1_MARKS1 WITH KEYWORDS ‘DELETE CASCADE’. SQL> INSERT INTO MCA1_MARKS1 VALUES(11. SQL> DELETE FROM MCA1 WHERE ROLLNO=11. Table created.78). 1 row created.NOW IF WE TRY TO DELETE A ROW WITH ROLLNO=11.child record found NOW . FROM TABLE MCA1 . IT WILL SHOW ERROR MESSAGE BECAUSE IT WILL VIOLATE THE REFERENTIAL INTEGRITY RULE.81).SYS_C00814) violated .IN THIS CASE WHEN WE DELETE ONE ROW FROM MASTER TABLE THE RELATED ROWS IN TRANSACTION TABLE ARE AUTOMETICALLY DELETED.'VC++'.'13-DEC-2007'. SQL> INSERT INTO MCA1_MARKS1 VALUES(17. SQL> INSERT INTO MCA1_MARKS1 VALUES(11. MARKS NUMBER(3)).

SQL> DELETE FROM MCA1 WHERE ROLLNO=11. SQL> DELETE FROM MCA1 WHERE ROLLNO=11. Table dropped. ROLLNO SUBJECT EXAM_DATE MARKS --------.--------.---------. SO ANY DELETION CAN VIOLATE THE REFERENTIAL INTEGRITY CONSTRAINT. NOW WE CAN DELETE ANY ROW FROM THE MASTER TABLE.SYS_C00814) violated . FIRSTLY WE HAVE TO DROP MCA1_MARKS. CRRESPOUNDING ROWS IN TRANSACTION TABLE WILL BE DELETED AUTOMETICALLY.child record found SO. 1 row deleted.----------------------------------------11 VB 13-DEC-07 88 11 DATA BASE 11-DEC-07 78 17 VC++ 10-DEC-07 81 ----------------------------------------------------------------------EVEN NOW WE CANN’T DELETE ROW FROM MASTER TABLE BECAUSE PREVIOUS TRANSACTION TABLE ‘MCA1_MARKS’ IS PRESENT TILL NOW. SQL> DROP TABLE MCA1_MARKS.SQL> SELECT * FROM MCA1_MARKS1 . SQL> SELECT * FROM MCA1_MARKS1 . DELETE FROM MCA1 WHERE ROLLNO=11 * ERROR at line 1: ORA-02292: integrity constraint (SCOTT. ROLLNO SUBJECT EXAM_DATE MARKS ---------------------------------------------------------------------17 VC++ 10-DEC-07 81 -------------------------------------------------------------------------- .

SQL> INSERT INTO MCA1_MARKS1 VALUES(20.-------------------------------------1 12 KULDEEP SAINI DATA BASE 77 3 20 PRADEEP CHAHAR VB 58 5 17 SAGAR PANCHAL VC++ 81 ----------------------------------------------------------------------------------------------/****************************OUTTER JOIN***********************************/ SQL> SELECT SNO.MCA1.77).NAME.MARKS FROM MCA1. SQL> SELECT SNO.'DATA BASE'. SQL> INSERT INTO MCA1_MARKS1 VALUES(12.ROLLNO.ROLLNO=MCA1_MARKS1.--------.-------------------.MCA1_MARKS1 3 WHERE MCA1.SUBJECT.'12-DEC-2007'.-------------------.ROLLNO.SUBJECT.NAME.MARKS 2 FROM MCA1.MCA1.'14-DEC-2007'.ROLLNO=MCA1_MARKS1.ROLLNO.---------. FIRSTY WE WILL ADD SOME ROWS IN ‘MCA1_MARKS1’./*****************************JOIN OPERATION********************************/ WE WILL PERFORM JOIN OPERATION ON MCA1_MARKS1 AND MCA1.MCA1_MARKS1 WHERE MCA1.--------5 17 SAGAR PANCHAL 3 20 PRADEEP CHAHAR 1 12 KULDEEP SAINI 2 22 RAKESH SINGHMAR SUBJECT ----------------VC++ VB DATA BASE MARKS -----------81 58 77 ------------------------------------------------------------------------------------------------------------ .'VB'.58). SNO ROLLNO NAME --------.--------. SNO ROLLNO NAME SUBJECT MARKS --------. 1 row created.ROLLNO(+). 1 row created.

ROLLNO.MCA1_MARKS1 M1 3 WHERE M.-----------------------KULDEEP SAINI MCA RAKESH SINGHMAR MCA PRADEEP CHAHAR MCA SAGAR PANCHAL MCA -------------------------------------------- . SNO ROLLNO NAME SUBJECT MARKS --------.M. SQL> SELECT NAME "FNAME"./**************************SOME SPECIAL COMMANDS******************************/ (1) WE CAN USE ALIAS OF TABLES AS IN THE FOLLOWING COMMANDS.---------. SQL> SELECT SNO.SUBJECT.ROLLNO=M1.--------.---------------------------------5 17 SAGAR PANCHAL VC++ 81 3 20 PRADEEP CHAHAR VB 58 1 12 KULDEEP SAINI DATA BASE 77 2 22 RAKESH SINGHMAR ------------------------------------------------------------------------------------------------------- (2) WE CAN DISPLAY ANY STRING INSTEAD OF ATTRIBUTES OF TABLE.ROLLNO(+).MARKS 2 FROM MCA1 M.-------------------.COURSE "PG" FROM MCA1.NAME. FNAME PG ------------------.

SQL> SELECT NAME.(3) WE CAN PERFORM SOME CALCULATION ON THE ATTRIBUTES VALUES OF A TABLE.SNO+ROLLNO "NET" FROM MCA1.-------------------------KULDEEP SAINI 13 RAKESH SINGHMAR 24 PRADEEP CHAHAR 23 SAGAR PANCHAL 22 --------------------------------------------- . NAME NET -------------------.

/************************************DUAL TABLE***********************************/ IT IS PREDEFINED TABLE PROVIDED BY SQL .52532199 SQL> SELECT CEIL(123. USER --------------SCOTT SQL> SELECT LN(1)FROM DUAL.55) FROM DUAL. SQL> SELECT SYSDATE FROM DUAL. DUAL TABLE IS USE TO VARIFY ANY PREDEFINED FUNCTIONS WHICH ARE ALSO PROVIDED BY SQL. COS(45) ----------------. SYSDATE ---------------20-NOV-07 SQL> SELECT USER FROM DUAL.55) -----------124 . LN(1) ---------------0 SQL> SELECT COS(45) FROM DUAL. CEIL(123.

./*********************************ALTER COMMAND*********************************/ WE CAN DO FOLLOWING CHANGES IN A TABLE BY ALTER COMMAND (1) ADD NEW COLUMN IN A TABLE SQL>ALTER TABLE MCA MODIFY (UNIVERSITY CHAR(15) DEFAULT ‘GJUST(HISAR)’).--------. SQL> UPDATE MCA SET UNIVERSITY = ‘GJUST(HISAR)’ 5 rows updated.--------. SQL> SELECT * FROM MCA.-------------------. SNO NAME ROLLNO DOB COURSE S AGE GRA UNIVERSITY --------.-----.--.-------------------------------------------------------1 KULDEEP SAINI 12 21-OCT-86 MCA M 21 A GJUST(HISAR) 2 RAKESH SINGHMAR 22 23-DEC-83 MCA M 23 A+ GJUST(HISAR) 3 PRADEEP CHAHAR 20 15-JAN-85 MCA M 22 A GJUST(HISAR) 4 SIMRAN PANCHAL 11 04-APR-86 MCA F 21 A++ GJUST(HISAR) 5 SAGAR PANCHAL 17 06-MAR-85 MCA M 22 A+ GJUST(HISAR) ---------------------------------------------------------------------------------------------------------------------------------- .-------------------.--------. SO TO UPDATE TABLE WE USE UPDATE COMMAND.-----.--.--------. SNO NAME ROLLNO DOB COURSE S AGE GRA UNIVERSITY --------. Table altered SQL>SELECT * FROM MCA.---------------------------------------------------------1 KULDEEP SAINI 12 21-OCT-86 MCA M 21 A+ 2 RAKESH SINGHMAR 22 23-DEC-83 MCA M 23 A+ 3 PRADEEP CHAHAR 20 15-JAN-85 MCA M 22 A 4 SIMRAN PANCHAL 11 04-APR-86 MCA F 21 A++ 5 SAGAR PANCHAL 17 06-MAR-85 MCA M 22 A+ -----------------------------------------------------------------------------------------------------------------------------------NOW AS WE CAN SEE VALUES CORESSPOUNDING TO ‘UNIVERSITY’ COLUMN ARE NULL .--------..--------.

-------. Name Null? Type ------------------------------.(2) TO ADD AND REMOVE PRIMARY KEY CONSTRAINT. SQL> DESC MCA Name Null? Type ------------------------------.-----------------------SNO NUMBER NAME CHAR(20) ROLLNO NUMBER DOB DATE COURSE CHAR(6) S CHAR(1) AGE NUMBER GRADE VARCHAR2(3) UNIVERSITY CHAR(15) ------------------------------------------------------------------ . Table altered. SQL> DESCRIBE MCA. Table altered.-------. SQL> ALTER TABLE MCA ADD PRIMARY KEY(ROLLNO).---------------------------SNO NUMBER NAME CHAR(20) ROLLNO NOT NULL NUMBER DOB DATE COURSE CHAR(6) S CHAR(1) AGE NUMBER GRADE VARCHAR2(3) UNIVERSITY CHAR(15) ---------------------------------------------------------------------SQL> ALTER TABLE MCA DROP PRIMARY KEY.

Name Null? Type ------------------------------.------------------------SNO NUMBER NAME CHAR(20) ROLLNO NOT NULL NUMBER DOB DATE COURSE CHAR(6) S CHAR(1) AGE NUMBER GRADE VARCHAR2(3) UNIVERSITY CHAR(15) ----------------------------------------------------------------- .-------. Table altered. Name Null? Type ------------------------------. SQL> ALTER TABLE MCA MODIFY NAME NOT NULL.-----------------------SNO NUMBER NAME NOT NULL CHAR(20) ROLLNO NOT NULL NUMBER DOB DATE COURSE CHAR(6) S CHAR(1) AGE NUMBER GRADE VARCHAR2(3) UNIVERSITY CHAR(15) ---------------------------------------------------------------SQL> ALTER TABLE MCA MODIFY NAME NULL.(3 )TO ADD AND REMOVE ‘NOT NULL’ CONSTRAINT.-------. Table altered. SQL> DESC MCA. SQL> DESC MCA.

Table altered.----------------------------------SNO NUMBER NAME CHAR(20) ROLLNO NOT NULL NUMBER DOB DATE COURSE CHAR(6) S CHAR(1) AGE NUMBER GRADE VARCHAR2(3) UNIVERSITY CHAR(15) --------------------------------------------------------------------------SQL> ALTER TABLE MCA DROP CONSTRAINT PR1.-----------------------------------SNO NUMBER NAME CHAR(20) ROLLNO NUMBER DOB DATE COURSE CHAR(6) S CHAR(1) AGE NUMBER GRADE VARCHAR2(3) UNIVERSITY CHAR(15) ----------------------------------------------------------------------------- . SQL> DESC MCA Name Null? Type ------------------------------. Name Null? Type ------------------------------.(4) WE CAN GIVE A PARTICULAR NAME TO ANY CONSTRAINT. Table altered.-------.-------. SQL> DESC MCA. SQL> ALTER TABLE MCA ADD CONSTRAINT PR1 PRIMARY KEY(ROLLNO).

User altered. NOW THE PASSWORD CHANGED FROM ‘TIGER’ TO ‘MUSKAN’. .(5) WE CAN CHANGE THE PASSWORD OF THE USER. SQL> ALTER USER SCOTT IDENTIFIED BY MUSKAN.

SNO NAME ROLLNO --------.--------------------------------1 KULDEEP SAINI 12 2 RAKESH SINGHMAR 22 3 PRADEEP CHAHAR 20 4 SIMRAN PANCHAL 11 5 SAGAR PANCHAL 17 --------------------------------------------------------------. SQL> DESC MCA Name Null? Type ------------------------------.-----------------SNO NUMBER NAME CHAR(20) ROLLNO NUMBER ---------------------------------------------------------SQL> SELECT * FROM MCA_VIEW.NAME .-------./****************************CREATING A VIEW OF A TABLE************************/ SQL> CREATE VIEW MCA_VIEW AS 2 SELECT SNO.-------------------. . View created.-------.---------------SNO NUMBER NAME CHAR(20) ROLLNO NUMBER DOB DATE COURSE CHAR(6) S CHAR(1) AGE NUMBER GRADE VARCHAR2(3) UNIVERSITY CHAR(15) ---------------------------------------------------------SQL> DESC MCA_VIEW. Name Null? Type ------------------------------.ROLLNO 3 FROM MCA.

TO DROP THE VIEW WE WILL WRITE THE FOLLOWING COMMAND.. SQL> DROP VIEW MCA_VIEW. View dropped. .