Sei sulla pagina 1di 4

deletefromEXNO:2 INTEGRITY CONSTRAINT

DATE:

SQL> create table basestud(rollno char(3) primary key,name varchar(10),mark1 number(3),mark2


number(3),sem char(2),dept char(3));

Table created.

SQL> create table stuaddress(rollno char(3) references basestud,add1 varchar2(10),add2 varchar2(10)


default 'xxx',pincode number(6),mobno number(10));

Table created.

SQL> create table hostel(rollno char(3) references basestud on delete cascade, roomno number(3),

fees number(5) constraint check_fees check(fees between 2000 and 20000));

Table created.

SQL> alter table stuaddress add constraint nn_no primary key(mobno);

Table altered.

SQL> desc stuaddress

Name Null? Type


ROLLNO CHAR(3)
ADD1 VARCHAR2(10)
ADD2 VARCHAR2(10)
PINCODE NUMBER(6)
MOBNO NOT NULL NUMBER(10)
SQL> desc basestud;

Name Null? Type


ROLLNO NOT NULL CHAR(3)
NAME VARCHAR2(10)
MARK1 NUMBER(3)
MARK2 NUMBER(3)
SEM CHAR(2)
DEPT CHAR(2)
SQL> insert into basestud(rollno,name,mark1,mark2,sem,dept values('itb','sabee',89,89,'1','IT');
1 row created.

SQL> insert into basestud(rollno,name,mark1,mark2,sem,dept)values('ita','srinithya',90,90,'2','CS');

1 row created.

SQL> insert into basestud(rollno,name,mark1,mark2,sem,dept)values('itc','praba',89,98,'3','ECE');

1 row created.

SQL> select* from basestud;

ROL NAME MARK1 MARK2 SE DEPT


itb sabee 89 89 1 IT
ita srinithya 90 90 2 CS
itc praba 89 98 3 ECE
SQL> insert into stuaddress(rollno,add1,add2,pincode,mobno) values('itb','101-gobi','121-salem',6549

89,9874837890);

1 row created.

SQL> insert into stuaddress(rollno,add1,add2,pincode,mobno)values('itd','34-tukey','23-cochi',


876823,976583254);

insert into stuaddress(rollno,add1,add2,pincode,mobno)values('itc','34-tukey', '23-cochi', 876823,


976583254);

ERROR at line 1:

ORA-O2291:integrity constraint (IT69.SYS_C005695)violated -parent key not found

SQL> insert into stuaddress(rollno,add1,add2,pincode,mobno) values('ita','122-delhi','132-gobi',7637

24,976875980);

1 row created.

SQL> select * from stuaddress;

ROL ADD1 ADD2 PINCODE MOBNO


itb 101-gobi 121-salem 654989 9874837890
ita 122-delhi 132-gobi 763724 976875980
itc 14-sankari 13-pillu 765683 9865983934
SQL> alter table hos1 modify (fees number(5));
Table altered.

SQL> insert into hostel(rollno,roomno,fees) values('itb',212,2000);

1 row created.

SQL> insert into hos1(rollno,roomno,fees) values('itd',342,4300);

insert into hos1(rollno,roomno,fees) values('itd',342,4300)

ERROR at line 1:

ORA-02291: integrity constraint (IT69.SYS_C005698) violated - parent key not found

SQL> insert into hostel(rollno,roomno,fees) values('itd',342,1000);

insert into hostel(rollno,roomno,fees) values('itd',342,1000)

ERROR at line 1:

ORA-02290: check constraint (IT69.CHECK_FEES) violated

SQL> select *from hostel;

ROL ROOMNO FEES


itb 212 2000
ita 211 3000
itc 342 4500

SQL> select rollno, roomno,fees from hos1 where fees between 2000 and 20000;

ROL ROOMNO FEES

itb 212 2000

ita 211 3000

itc 342 4500

SQL> delete from basestud where rollno='itc';

delete from basestud where rollno='itc'

ERROR at line 1:

ORA-02292: integrity constraint (IT69.SYS_C005696) violated - child record

Found
SQL> delete from stuaddress where rollno='itc';

1 row deleted.

SQL> delete from basestud where rollno='itc';

1 row deleted.

SQL> delete from stuaddress where rollno='itb';

1 row deleted.

SQL> select * from basestud;

ROL NAME MARK1 MARK2 SE DEP

itb sabee 89 89 1 IT

ita srinithya 90 90 2 CS

SQL> delete from basestud where rollno='itb';

1 row deleted.

SQL> select * from basestud;

ROL NAME MARK1 MARK2 SE DEP

ita srinithya 90 90 2 CS

SQL> select * from hos1;

no rows selected

Potrebbero piacerti anche