SELECT sysobjects.id objectId , OBJECT_NAME(sysobjects.parent_obj) tableName , sysobjects.name constraintName , sysobjects.xtype AS constraintType , syscolumns.name AS columnName FROM sysobjects INNER JOIN sysconstraints ON sysobjects.xtype IN ( 'C', 'F', 'PK', 'UQ', 'D' ) AND sysobjects.id = sysconstraints.constid LEFT OUTER JOIN syscolumns ON sysconstraints.id = syscolumns.id WHERE OBJECT_NAME(sysobjects.parent_obj) = 'tableName'
(转自:鼠U猫)