Tuesday, July 20, 2010

On Deletion/Updation Of a Primary Key, Foreign Key will be Deleted Automatically

create table a(ID int Primary key , MyName varchar(100))

create table ab(ID int foreign key references a(ID) on update cascade, Address1 varchar(100))

create table abc(ID int foreign key references a(ID) on update cascade, Address2 varchar(100))

insert into a(ID,MyName) values(1,'Bikash')
insert into ab(ID,Address1) values(1,'Getit')
insert into abc(ID,Address2) values(1,'Tej Building')

drop table a
drop table ab
drop table abc

delete from a where id=1
update a set id=4

In the above query, there is more synchronisation between master and Transaction. When we will delete/Update in Master table, Transaction will be updated/deleted Automatically

1 comment:

Pawan Kamboj said...

Very useful query, Because in normal cases, we use to /update delete from transaction first.

Pawan Kamboj