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
 General SQL Server Forums
 New to SQL Server Programming
 Table to table relation

Author  Topic 

feejaz
Yak Posting Veteran

68 Posts

Posted - 2008-01-30 : 07:41:59
Hi,
Any one tell me how to get table to table relation I want to Delete both Table's row When I am going to delete Record from One table.

Thanks

Navi

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-30 : 07:50:03
http://msdn2.microsoft.com/en-us/library/ms186973.aspx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-01-30 : 07:51:30
Make a Primary-Foreign key relation ship between two tables and use ON DELETE CASCADE option.

Like,
Create Table tMaster

(

id Int Primary Key,

sName varchar(20)

)



Create Table tChild

(
id Int Primary Key,
mid Int References tMaster(id) ON DELETE CASCADE,
SName varchar(20)

)

Go to Top of Page

feejaz
Yak Posting Veteran

68 Posts

Posted - 2008-01-30 : 10:53:12
Thanks that is working.

I need Create script. How can I create script only for relation.
I have to insert the primary key, Delete Column, Rename table, and defaultvalue set to zero through Script.
Thanks

Navi
Go to Top of Page

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-01-30 : 23:50:26
Search Books online.You will get ample help on google too. Come up with what you get and then forum can help you improve it.
Go to Top of Page
   

- Advertisement -