すべての制約に関心があるかどうかはわかりませんが、INFORMATION_SCHEMA.TABLE_CONSTRAINTSがDEFAULT制約を返さないようです-TABLE_CONSTRAINTS(Transact-SQL)
チェック、一意、主キー、外部キー
このクエリは、sys.objects DMVに対して単純なカウントを行います。
select COUNT(*)
from sys.objects o
where o.type_desc like '%CONSTRAINT%';
テーブルの一覧表示に興味がある場合は、次のように実行できます。
select distinct
o.object_id
, QUOTENAME(s.name) + '.' + QUOTENAME(o.name) as [object_name]
, o.type_desc
, case when dc.parent_object_id is null then 'No' else 'Yes' end as has_default_constraint
, case when cc.parent_object_id is null then 'No' else 'Yes' end as has_check_constraint
, case when fk.parent_object_id is null then 'No' else 'Yes' end as has_foreing_key
, case when kc.parent_object_id is null then 'No' else 'Yes' end as has_primary_key
from sys.objects o
inner join sys.schemas s on s.schema_id = o.schema_id
left outer join sys.default_constraints dc on dc.parent_object_id = o.object_id and dc.schema_id = o.schema_id
left outer join sys.check_constraints cc on cc.parent_object_id = o.object_id and cc.schema_id = o.schema_id
left outer join sys.foreign_keys fk on fk.parent_object_id = o.object_id and fk.schema_id = o.schema_id
left outer join sys.key_constraints kc on kc.parent_object_id = o.object_id and kc.schema_id = o.schema_id
where o.is_ms_shipped = 0
and o.type = 'U'
order by [object_name];
これはあなたのインデックスに関する情報を与えるはずです:
select o.name
, i.*
from sys.objects o
inner join sys.indexes i on i.object_id = o.object_id
where o.is_ms_shipped = 0
and i.object_id > 100
and i.index_id > 0
order by o.name
, i.index_id;
- Index_Id = 0-HEAP(表示されません)
- Index_Id = 1-CLUSTERED
- Index_Id> 1-不要
object_id > 100
か説明してもらえますか?