FK _ foreign key
Select tab for primary key constraints. name as [Table name], idx. name as [primary key name], Col. name as [primary key column name] From sys. indexes idx join sys. index_columns idxcol on (idx. object_id = idxcol. object_id and idx. index_id = idxcol. index_id and idx. is_primary_key = 1) join sys. tables tab on (idx. object_id = tab. object_id) join sys. columns Col on (idx. object_id = Col. object_id and idxcol. column_id = Col. column_id); the only constraint is select tab. name as [Table name], idx. name as [constraint name], Col. name as [constraint column name] From sys. indexes idx join sys. index_columns idxcol on (idx. object_id = idxcol. object_id and idx. index_id = idxcol. index_id and idx. is_unique_constraint = 1) join sys. tables tab on (idx. object_id = tab. object_id) join sys. columns Col on (idx. object_id = Col. object_id and idxcol. column_id = Col. column_id); foreign key constraint select osub. name as [subtable name], FK. name as [foreign key name], subcol. name as [subtable column name], omain. name as [master table name], maincol. name as [primary table column name] From sys. foreign_keys FK join sys. all_objects osub on (FK. parent_object_id = osub. object_id) join sys. all_objects omain on (FK. referenced_object_id = omain. object_id) join sys. foreign_key_columns fkcols on (FK. object_id = fkcols. constraint_object_id) join sys. columns subcol on (osub. object_id = subcol. object_id and fkcols. parent_column_id = subcol. column_id) join sys. columns maincol on (omain. object_id = maincol. object_id and fkcols. referenced_column_id = maincol. column_id) Check constraints select tab. name as [Table name], chk. name as [Check constraint name], Col. name as [column name], chk. definitionfrom sys. check_constraints chk join sys. tables tab on (chk. parent_object_id = tab. object_id) join sys. columns Col on (chk. parent_object_id = Col. object_id and chk. parent_column_id = Col. column_id)