Escolar Documentos
Profissional Documentos
Cultura Documentos
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options
SQL> REM>DISCARDING ALL TABLES SQL> drop table reservation; drop table reservation * ERROR at line 1: ORA-00942: table or view does not exist
SQL> drop table sailor; drop table sailor * ERROR at line 1: ORA-00942: table or view does not exist
SQL> drop table tourist; drop table tourist * ERROR at line 1: ORA-00942: table or view does not exist
SQL> drop table boat; drop table boat * ERROR at line 1: ORA-00942: table or view does not exist
SQL> drop table boat; drop table boat * ERROR at line 1: ORA-00942: table or view does not exist
Commit complete.
SQL> create table boat(id number(5) primary key,name varchar(10),type varchar(10),capacity number(10),price number(10),colour varchar(10));
Table created.
SQL> REM>QUERY 1:ADDING CONSTRAINT FOR BOAT TYPE SQL> alter table boat add constraint boat_type check(type='lux' or type='car' or type='cru');
Table altered.
1 row created.
1 row created.
1 row created.
ID NAME
TYPE
CAPACITY
PRICE COLOUR
---------- ---------- ---------- ---------- ---------- ---------1001 Hydro lux 100 75 50 100 pink 75 yellow 50 green
SQL> REM> CHECKING BOAT TYPE CONSTRAINT SQL> insert into boat values(1004,'Wiper','yacht',80,80,'orange'); insert into boat values(1004,'Wiper','yacht',80,80,'orange') * ERROR at line 1: ORA-02290: check constraint (SCOTT.BOAT_TYPE) violated
SQL> REM> CREATING TABLE SAILOR SQL> create table sailor(id number(5) primary key,name varchar(10),rating varchar(10),dob date);
Table created.
SQL> REM>QUERY 2: ADDING CONSTRAINT RATING FOR A SAILOR SQL> alter table sailor add constraint rating_type check(rating='a' or rating='b' or rating='c');
Table altered.
SQL> REM> INSERTING VALUES TO SAILOR TABLE SQL> insert into sailor values(2001,'lokkesh','a','30-AUG-1993');
1 row created.
1 row created.
1 row created.
ID NAME
RATING
DOB
---------- ---------- ---------- --------2001 lokkesh a 2002 ram c 30-AUG-93 11-FEB-90 13-JAN-95
2003 sujitha b
SQL> insert into sailor values(2004,'siva','d','10-NOV-1980'); insert into sailor values(2004,'siva','d','10-NOV-1980') * ERROR at line 1: ORA-02290: check constraint (SCOTT.RATING_TYPE) violated
Commit complete.
SQL> create table tourist(tno number(10) primary key,address varchar(10),dob date,phone number(10));
Table created.
SQL> REM> ENTERING VALUES TO TOURISTS TABLE SQL> insert into tourist values(3001,'chennai','30-AUG-1995',9884031447);
1 row created.
Table dropped.
SQL> create table tourist(tno number(10) primary key,name varchar(10),address varchar(10),dob date,phone number(10));
Table created.
insert into tourist values (3001,'ramesh','30-AUG-1995',9444243166) * ERROR at line 1: ORA-00947: not enough values
SQL> REM> ERROR ABOVE SQL> insert into tourist values (3001,'ramesh','chennai','30-AUG-1995',9884031447);
1 row created.
1 row created.
SQL> insert into tourist values (3003,'suganya','madurai','30-JAN-2000',99401701826); insert into tourist values (3003,'suganya','madurai','30-JAN-2000',99401701826) * ERROR at line 1: ORA-01438: value larger than specified precision allowed for this column
1 row created.
TNO NAME
ADDRESS DOB
PHONE
3001 ramesh
3002 praveen kachipuram 12-NOV-80 8939155347 3003 suganya madurai 30-JAN-00 9940170182
SQL> commit;
Commit complete.
SQL> REM> CREATING TABLE RESERVATION SQL> REM>QUERY 6,7,15 SQL> create table reservation(bno number(10),sno number(10),tno number(10),primary key(bno,sno,tno),dos date,dor date);
Table created.
SQL> alter table reservation add constraint res_fk1 foreign key (bno) references boat(id) on delete cascade;
Table altered.
SQL> alter table reservation add constraint res_fk2 foreign key (sno) references sailor(id) on delete cascade;
Table altered.
SQL> alter table reservation add constraint res_fk3 foreign key (tno) references tourist(tno) on delete cascade;
Table altered.
SQL> REM>QUERY 3 SQL> alter table reservation add constraint dos_check check(dos-dor<=12);
Table altered.
1 row created.
BNO
SNO
TNO DOS
DOR
SQL> REM> VIOLATING QUERY 3 SQL> insert into reservation values(1001,2001,3001,'31-JAN-2014','08-JAN-2014'); insert into reservation values(1001,2001,3001,'31-JAN-2014','08-JAN-2014') * ERROR at line 1: ORA-02290: check constraint (SCOTT.DOS_CHECK) violated
SQL> REM> QUERY 4: SQL> alter table sailor add constraint age_check check(((months_between('20-JAN2014',dob))/12>25)); alter table sailor add constraint age_check check(((months_between('20-JAN-2014',dob))/12>25)) * ERROR at line 1: ORA-02293: cannot validate (SCOTT.AGE_CHECK) - check constraint violated
alter table sailor add constraint age_check check(((months_between('20-JAN-2014',dob))/12>25)) * ERROR at line 1: ORA-02293: cannot validate (SCOTT.AGE_CHECK) - check constraint violated
3 rows deleted.
SQL> REM> INSERTING INTO SAILOR TABLE SQL> alter table sailor add constraint age_check check(((months_between('20-JAN2014',dob))/12>25));
Table altered.
1 row created.
1 row created.
1 row created.
ID NAME
RATING
DOB
---------- ---------- ---------- --------2001 gautam 2002 sujitha b 2003 ram c a 29-OCT-83 23-JAN-72 18-FEB-89
SQL> insert into sailor values(2004,'kamal','c','22-OCT-2000'); insert into sailor values(2004,'kamal','c','22-OCT-2000') * ERROR at line 1: ORA-02290: check constraint (SCOTT.AGE_CHECK) violated
SQL> REM> QUERY 8 SQL> alter table tourist add no_child number(10);
Table altered.
SQL> insert into tourist values(3004,'rajiv','20-JUL-1995',8939303456,2); insert into tourist values(3004,'rajiv','20-JUL-1995',8939303456,2) * ERROR at line 1: ORA-00947: not enough values
1 row created.
TNO NAME
ADDRESS DOB
PHONE NO_CHILD
---------- ---------- ---------- --------- ---------- ---------3001 ramesh chennai 30-AUG-95 9884031447
3002 praveen kachipuram 12-NOV-80 8939155347 3003 suganya madurai 30-JAN-00 9940170182 3004 rajiv banglore 20-JUL-95 8939303456 2
Commit complete.
SQL> REM>VIOLATION OF QUERY 9 SQL> insert into tourist values(3005,'vinod sharma','chennai','13-MAR-1994',9445623466,3); insert into tourist values(3005,'vinod sharma','chennai','13-MAR-1994',9445623466,3) * ERROR at line 1: ORA-12899: value too large for column "SCOTT"."TOURIST"."NAME" (actual: 12, maximum: 10)
Table altered.
1 row created.
SQL> REM > DISPLAY TOURIST TABLE AFTER ALTERATION & INSERTION SQL> select * from tourist;
TNO NAME
ADDRESS DOB
PHONE NO_CHILD
---------- -------------------- ---------- --------- ---------- ---------3001 ramesh 3002 praveen 3003 suganya 3004 rajiv chennai 30-AUG-95 9884031447 kachipuram 12-NOV-80 8939155347 madurai 30-JAN-00 9940170182 banglore 20-JUL-95 8939303456 2 3
SQL> commit;
Commit complete.
SQL> REM>QUERY 10 SQL> alter table reservation modify dor not null;
Table altered.
SQL> insert into reservation values(1001,2001,3001,,'23-DEC-2003'); insert into reservation values(1001,2001,3001,,'23-DEC-2003') * ERROR at line 1: ORA-00936: missing expression
1 row created.
BNO
SNO
TNO DOS
DOR
SQL> REM>QUERY 13 SQL> REM> QUERY 12 SQL> alter table sailor drop constraint rating_type;
Table altered.
SQL> alter table sailor add constraint rating_type check(rating='a' or rating='b' or rating='c' or rating='d');
Table altered.
1 row created.
ID NAME
RATING
DOB
---------- ---------- ---------- --------2001 gautam 2002 sujitha b 2003 ram 2006 friend c d a 29-OCT-83 23-JAN-72 18-FEB-89 19-MAR-80
ID NAME
TYPE
CAPACITY
PRICE COLOUR
---------- ---------- ---------- ---------- ---------- ---------1001 Hydro lux 100 75 50 100 pink 75 yellow 50 green
1 row updated.
ID NAME
TYPE
CAPACITY
PRICE COLOUR
---------- ---------- ---------- ---------- ---------- ---------1001 Hydro lux 100 75 50 100 yellow 75 yellow 50 green
SQL> REM> VIOLATION OF QUERY 13 SQL> alter table boat add constraint boat_colour check(type='lux' and colour='yellow'); alter table boat add constraint boat_colour check(type='lux' and colour='yellow') * ERROR at line 1: ORA-02293: cannot validate (SCOTT.BOAT_COLOUR) - check constraint violated
SQL> REM>QUERY 14
Table altered.
ID NAME
TYPE
CAPACITY
PRICE COLOUR
---------- ---------- ---------- ---------- ---------- ---------1001 Hydro lux 100 75 50 100 yellow 75 yellow 50 green
SQL> REM > QUERY 14 VIOLATION SQL> insert into boat values(1004,'Hydro','car',50,50,'red'); insert into boat values(1004,'Hydro','car',50,50,'red') * ERROR at line 1: ORA-00001: unique constraint (SCOTT.BOAT_U) violated
SQL> commit;
Commit complete.
----------------------------------------- -------- ---------------------------TNO NAME ADDRESS NOT NULL NUMBER(10) VARCHAR2(20) VARCHAR2(10)
TNO NAME
ADDRESS DOB
PHONE NO_CHILD
---------- -------------------- ---------- --------- ---------- ---------3001 ramesh 3002 praveen 3003 suganya 3004 rajiv chennai 30-AUG-95 9884031447 kachipuram 12-NOV-80 8939155347 madurai 30-JAN-00 9940170182 banglore 20-JUL-95 8939303456 2 3
BNO
SNO
TNO DOS
DOR
SQL> insert into reservation values(1001,2001,3001,'24-jan-2013','25-jan-2013'); insert into reservation values(1001,2001,3001,'24-jan-2013','25-jan-2013') * ERROR at line 1: ORA-00001: unique constraint (SCOTT.SYS_C005471) violated
ID NAME
TYPE
CAPACITY
PRICE COLOUR
1001 Hydro
lux
100 75 50
SQL> drop table boat; drop table boat * ERROR at line 1: ORA-02449: unique/primary keys in table referenced by foreign keys
SQL> REM> QUERY 15 Deleting from boat SQL> delete from boat where id=1001;
1 row deleted.
no rows selected