Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to delete a record of primarykey

Author  Topic 

umapathy
Starting Member

24 Posts

Posted - 2007-12-05 : 06:01:41
Hi

i have a two tables namely x,y.the desing structure of the table is below mentioned

x

id(primary key) address
1 abc
2 xyz
3 asd

y

name date id(foriegn key)

abc 2/dec/07 1
xyz 3/dec/07 2


here am want to delete id value 1 from table x. but it didn't allowe me to delete.then how can i delete a record from table x.

Thanks
Umapathy



harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-12-05 : 06:06:42
You have to delete child table's i.e. table y's - related record first before deleting record from X.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-05 : 11:46:06
You can also make this happen automatically by using clause ON DELETE CASCADE with foreign key definition (i.e definition of col [name] in table y in the example).Then if you try to delete record with id 1, it will automatically delete the child tables record first and then deletes the main table record.
Go to Top of Page
   

- Advertisement -