Anda di halaman 1dari 9

SQL> set autocommit on; SQL> create table Employee as select * from chandan.Employee; Table created.

SQL> create table Dept as select * from chandan.Dept; create table Dept as select * from chandan.Dept * ERROR at line 1: ORA-00955: name is already used by an existing object SQL> create table Dept1 as select * from chandan.Dept; Table created. SQL> create table Dept_loc as select * from chandan.Dept_loc; Table created. SQL> create table Works_ON as select * from chandan.Works_ON; Table created. SQL> create table Project as select * from chandan.Project; Table created. SQL> create table Dependent as select * from chandan.Dependent; Table created. SQL> ed e1; SQL> @ e1; Table altered. SQL> ed e1; SQL> @ e1; alter table Dept1 add constraint cons_pk primary key(dnum) * ERROR at line 1: ORA-00904: "DNUM": invalid identifier SQL> ed e1; SQL> @ e1; alter table Dept1 add constraint cons_pk primary key(dno) * ERROR at line 1: ORA-02264: name already used by an existing constraint SQL> desc Usage: DESCRIBE [schema.]object[@db_link] SQL> desc Dept1 Name Null?

Type

----------------------------------------- -------- ---------------------------DNAME VARCHAR2(15) DNO NUMBER(3) MGRSSN NUMBER(5) MGRSTDATE DATE SQL> ed e1; SQL> @ e1; alter table Dept1 add constraint cons_pk primary key(dno) * ERROR at line 1: ORA-02264: name already used by an existing constraint SQL> alter table Dept1 drop constraint cons_pk; alter table Dept1 drop constraint cons_pk * ERROR at line 1: ORA-02443: Cannot drop constraint - nonexistent constraint SQL> ed e1; SQL> ed e1; SQL> @ e1; Table altered. SQL> ed e1; SQL> desc Project; Name Null? ----------------------------------------- -------PNAME PNO PLOC DNO SQL> ed e1; SQL> @ e1; Table altered. SQL> ed e1; SQL> desc Employee; Name Null? ----------------------------------------- -------FNAME MNAME LNAME SSN NOT NULL BDATE ADDR SEX SALARY SUPERSSN Type ---------------------------VARCHAR2(8) VARCHAR2(8) VARCHAR2(8) NUMBER(5) DATE VARCHAR2(20) VARCHAR2(1) NUMBER(7,2) NUMBER(5) Type ---------------------------VARCHAR2(15) NUMBER(3) VARCHAR2(15) NUMBER(3)

DNO SQL> ed e1;

NUMBER(3)

SQL> @ e1; alter table Employee add constraint emp_fk foreign key (dno) references Employee (dno) * ERROR at line 1: ORA-02270: no matching unique or primary key for this column-list SQL> ed e1; SQL> ed e1; SQL> @ e1; Table altered. SQL> ed e1; SQL> @ e1; alter table Dept1 add constraint dept_fk foreign key (mgrssn) reference Employee (ssn) * ERROR at line 1: ORA-00905: missing keyword SQL> ed e1; SQL> @ e1; Table altered. SQL> ed e1; SQL> ed e1; SQL> @ e1; Table altered. SQL> ed e1; SQL> @ e1; Table altered. SQL> ed e1; SQL> desc Works_ON; Name Null? ----------------------------------------- -------ESSN PNO HOURS Type ---------------------------NUMBER(5) NUMBER(3) NUMBER(3)

SQL> ed e1; SQL> @ e1; Table altered. SQL> ed e1; SQL> desc Dependent; Name Null? ----------------------------------------- -------ESSN DEPNAME SEX BDATE RELATIONSHIP SQL> ed e1; SQL> @ e1; Table altered. SQL> ed e1; SQL> @ e1; Table altered. SQL> ed e1; SQL> @ e1; Table altered. SQL> ed e1; SQL> select * from Employee; FNAME MNAME LNAME SSN BDATE ADDR S -------- -------- -------- ---------- --------- -------------------- SALARY SUPERSSN DNO ---------- ---------- ---------john B smith 1234 09-JAN-65 731 fondren M 30000 3334 5 Frankin T 40000 Allicia j 25000 wong 8886 Zelaya 9876 3334 08-DEC-55 638 voss,Tx 5 9998 19-JAN-68 3321 castle,spring 4 F M Type ---------------------------NUMBER(5) VARCHAR2(10) VARCHAR2(1) DATE VARCHAR2(20)

FNAME MNAME LNAME SSN BDATE ADDR S -------- -------- -------- ---------- --------- -------------------- SALARY SUPERSSN DNO ---------- ---------- ---------jennifer s walace 9876 20-JUL-41 291 berry,bellarie f 43000 8886 4

Ramesh k 38000 joyce a 25000

Narayan 3334 English 3334

6668 15-SEP-62 975 fire oak,humble m 5 4534 31-JUL-72 5631 rice,houston 5 f

FNAME MNAME LNAME SSN BDATE ADDR S -------- -------- -------- ---------- --------- -------------------- SALARY SUPERSSN DNO ---------- ---------- ---------ahmad v jabber 9879 29-MAR-69 98D dallas,houston m 25000 9876 4 james e 25000 borg 1 8886 10-NOV-37 450 stone,houston m

8 rows selected. SQL> ed e1; SQL> @ e1; DNAME DNO DLOC --------------- ---------- ---------HEADQUARTER 1 Houston HEADQUARTER 1 Houston HEADQUARTER 1 stafford HEADQUARTER 1 bellaire HEADQUARTER 1 sugarland RESEARCH 5 Houston RESEARCH 5 Houston RESEARCH 5 stafford RESEARCH 5 bellaire RESEARCH 5 sugarland ADMINISTRATION 4 Houston DNAME DNO DLOC --------------- ---------- ---------ADMINISTRATION 4 Houston ADMINISTRATION 4 stafford ADMINISTRATION 4 bellaire ADMINISTRATION 4 sugarland 15 rows selected. SQL> ed e1; SQL> ed e1; SQL> select * from Project; PNAME PNO PLOC DNO --------------- ---------- --------------- ---------productx 1 bellaire 5 producty 2 sugarland 5 productz 3 houston 5 computerization 10 stafford 4 Reorganization 20 houston 1

Newbenefits 6 rows selected. SQL> ed e1; SQL> @ e1;

30 stafford

FNAME PNO PLOC -------- ---------- --------------john 1 bellaire Frankin 1 bellaire Allicia 1 bellaire jennifer 1 bellaire Ramesh 1 bellaire joyce 1 bellaire ahmad 1 bellaire james 1 bellaire john 2 sugarland Frankin 2 sugarland Allicia 2 sugarland FNAME PNO PLOC -------- ---------- --------------jennifer 2 sugarland Ramesh 2 sugarland joyce 2 sugarland ahmad 2 sugarland james 2 sugarland john 3 houston Frankin 3 houston Allicia 3 houston jennifer 3 houston Ramesh 3 houston joyce 3 houston FNAME PNO PLOC -------- ---------- --------------ahmad 3 houston james 3 houston john 10 stafford Frankin 10 stafford Allicia 10 stafford jennifer 10 stafford Ramesh 10 stafford joyce 10 stafford ahmad 10 stafford james 10 stafford john 20 houston FNAME PNO PLOC -------- ---------- --------------Frankin 20 houston Allicia 20 houston jennifer 20 houston Ramesh 20 houston joyce 20 houston ahmad 20 houston james 20 houston john 30 stafford

Frankin Allicia jennifer

30 stafford 30 stafford 30 stafford

FNAME PNO PLOC -------- ---------- --------------Ramesh 30 stafford joyce 30 stafford ahmad 30 stafford james 30 stafford 48 rows selected. SQL> ed e1; SQL> @ e1; FNAME -------john Allicia jennifer joyce ahmad james MNAME -------B j s a v e LNAME -------smith Zelaya walace English jabber borg

6 rows selected. SQL> ed e1; SQL> select * from dependent; ESSN ---------3334 3334 3334 9876 1234 1234 1234 DEPNAME ---------alice theodore joy abner michael alice elizabeth S f m f m m f f BDATE --------05-APR-86 25-OCT-83 03-MAY-58 28-FEB-42 04-JAN-88 30-DEC-88 05-MAY-67 RELATIONSHIP -------------------daughter son spouse spouse son daughter spouse

7 rows selected. SQL> ed e1; SQL> @ e1; FNAME -------john Frankin Allicia jennifer Ramesh joyce ahmad james john Frankin DEPNAME ---------alice alice alice alice alice alice alice alice theodore theodore

Allicia theodore FNAME -------jennifer Ramesh joyce ahmad james john Frankin Allicia jennifer Ramesh joyce FNAME -------ahmad james john Frankin Allicia jennifer Ramesh joyce ahmad james john FNAME -------Frankin Allicia jennifer Ramesh joyce ahmad james john Frankin Allicia jennifer FNAME -------Ramesh joyce ahmad james john Frankin Allicia jennifer Ramesh joyce ahmad DEPNAME ---------theodore theodore theodore theodore theodore joy joy joy joy joy joy DEPNAME ---------joy joy abner abner abner abner abner abner abner abner michael DEPNAME ---------michael michael michael michael michael michael michael alice alice alice alice DEPNAME ---------alice alice alice alice elizabeth elizabeth elizabeth elizabeth elizabeth elizabeth elizabeth

FNAME DEPNAME -------- ----------

james

elizabeth

56 rows selected. SQL> ed e1; SQL> select * from Project; PNAME PNO PLOC DNO --------------- ---------- --------------- ---------productx 1 bellaire 5 producty 2 sugarland 5 productz 3 houston 5 computerization 10 stafford 4 Reorganization 20 houston 1 Newbenefits 30 stafford 4 6 rows selected. SQL> ed e1; SQL> ed e1; SQL> @ e1; FNAME -------john Frankin Allicia jennifer Ramesh joyce ahmad james ADDR PNO -------------------- ---------731 fondren 2 638 voss,Tx 2 3321 castle,spring 2 291 berry,bellarie 2 975 fire oak,humble 2 5631 rice,houston 2 98D dallas,houston 2 450 stone,houston 2

8 rows selected. SQL> ed e1; SQL> spool off;

Anda mungkin juga menyukai