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.
| Author |
Topic |
|
amitm79
Starting Member
5 Posts |
Posted - 2004-01-29 : 23:07:06
|
| Hi All, Can anybody tell me how to find the definition of all the constraints on a particular table? My requirement is to find out all the tables referring a particular table through foreign key. sp_helpconstraint can show me the names of the constrains but not the definition.Regards,amitm79 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-01-30 : 04:11:37
|
| try this:select distinctobject_name(fkeyid) name_of_table_with_FK,object_name(constid) name_of_FKfrom sysforeignkeyswhere object_name(rkeyid)='name_of_the_table_with_PK' |
 |
|
|
raymondpeacock
Constraint Violating Yak Guru
367 Posts |
Posted - 2004-01-30 : 04:38:55
|
| This will also give you the column names of the foreign key and referenced columns: SELECT FKName = OBJECT_NAME(constid), FKTable = OBJECT_NAME(fkeyid), FKColumn = c1.name, RefTable = OBJECT_NAME(rkeyid), RefColumn = c2.name FROM sysforeignkeys fk LEFT JOIN syscolumns c1 ON fk.fkeyid = c1.id AND fk.fkey = c1.colid LEFT JOIN syscolumns c2 ON fk.rkeyid = c2.id AND fk.rkey = c2.colidRaymond |
 |
|
|
|
|
|