joecre
July 31st, 2003, 05:30 AM
SELECT
'if not exists (select* from dbo.sysobjects where (id = object_id(N'''+c_obj.name+'''))and OBJECTPROPERTY(id,N''IsConstraint'')=1) '
+' BEGIN '+
'ALTER TABLE ' + t_obj.name + ' ADD CONSTRAINT '+c_obj.name+
' FOREIGN KEY ' HERE ARE MISSING INFOS+
+' END '
AS Script
FROM sysobjects AS c_obj
LEFT OUTER JOIN syscomments AS com
ON c_obj.id = com.id
LEFT OUTER JOIN sysobjects AS t_obj
ON c_obj.parent_obj = t_obj.id
LEFT OUTER JOIN sysconstraints AS con
ON c_obj.id = con.constid
LEFT OUTER JOIN syscolumns AS col
ON t_obj.id = col.id and con.colid = col.colid
WHERE c_obj.xtype IN ('F') AND t_obj.name Like 'my_table'
to automatically add foreign keys in a table......
my question is : where can I find info on FK Constraints ?
I need to know which columns are used by the FK and if there are any clauses for CASCADE DELETE etc. etc.
Can someone suggest me a method ?
Thank you everybody
'if not exists (select* from dbo.sysobjects where (id = object_id(N'''+c_obj.name+'''))and OBJECTPROPERTY(id,N''IsConstraint'')=1) '
+' BEGIN '+
'ALTER TABLE ' + t_obj.name + ' ADD CONSTRAINT '+c_obj.name+
' FOREIGN KEY ' HERE ARE MISSING INFOS+
+' END '
AS Script
FROM sysobjects AS c_obj
LEFT OUTER JOIN syscomments AS com
ON c_obj.id = com.id
LEFT OUTER JOIN sysobjects AS t_obj
ON c_obj.parent_obj = t_obj.id
LEFT OUTER JOIN sysconstraints AS con
ON c_obj.id = con.constid
LEFT OUTER JOIN syscolumns AS col
ON t_obj.id = col.id and con.colid = col.colid
WHERE c_obj.xtype IN ('F') AND t_obj.name Like 'my_table'
to automatically add foreign keys in a table......
my question is : where can I find info on FK Constraints ?
I need to know which columns are used by the FK and if there are any clauses for CASCADE DELETE etc. etc.
Can someone suggest me a method ?
Thank you everybody