SELECT sc.constid ConstraintID,
so.name TableName,
CASE WHEN sc.colid = 0 THEN '' ELSE s.name END ColumnName,
CASE
WHEN sc.Status & 32 > 0 then 'Table-level'
WHEN sc.Status & 16 > 0 then 'Column-level'
WHEN sc.Status & 5 > 0 then 'DEFAULT'
WHEN sc.Status & 4 > 0 then 'CHECK'
WHEN sc.Status & 3 > 0 then 'FOREIGN KEY'
WHEN sc.Status & 2 > 0 then 'UNIQUE KEY'
WHEN sc.Status & 1 > 0 then 'PRIMARY KEY'
END + ' constraint'
FROM sysconstraints sc
INNER JOIN sysobjects so ON so.id = sc.id AND so.xtype = 'u'
LEFT JOIN syscolumns s ON s.colid = sc.colid AND so.id = s.id
Collection of unedited thoughts and bits of knowledge I can't seem to remember
Search This Blog
Wednesday, September 30, 2009
List constrainsts on a table
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment