以下兩個語句均基於系統表sysobjects、syscomments和系統檢視sysconstraints,查詢結果中包括表id、表名、列id、列名、check約束id、check約束名、check約束status值以及check約束的內容,tccview為table-column-check view,結果中均為列級check約束,tcview為table-check view,結果中均為表級check約束。
1.select top 100 percent a.id as tableid, a.tablename, a.colid, a.columnname,
a.datatype, a.length, b.constid as checkid, b.checkname, b.status, b.content
from (select sysobjects.name as tablename, sysobjects.id,
syscolumns.name as columnname, syscolumns.colid,
systypes.name as datatype, syscolumns.length as length
from sysobjects, syscolumns, systypes
where sysobjects.xtype = 'u' and sysobjects.id = syscolumns.id and
syscolumns.xtype = systypes.xtype and
systypes.xtype = systypes.xusertype and sysobjects.status > 0)
a left outer join
(select sysobjects.name checkname, sysobjects.status, sysconstraints.constid,
sysconstraints.id, sysconstraints.colid, syscomments.text as content
from sysobjects, sysconstraints, syscomments
where xtype = 'c' and sysobjects.id = sysconstraints.constid and
sysconstraints.constid = syscomments.id) b on a.id = b.id and
a.colid = b.colid
order by a.tablename, a.columnname, b.checkname
2.select a.id as tableid, a.tablename, b.constid as checkid, b.checkname, b.status,
b.content
from (select sysobjects.id, sysobjects.name as tablename
from sysobjects
where sysobjects.xtype = 'u' and sysobjects.status > 0) a left outer join
(select sysobjects.name checkname, sysobjects.status, sysconstraints.constid,
sysconstraints.id, sysconstraints.colid, syscomments.text as content
from sysobjects, sysconstraints, syscomments
where xtype = 'c' and sysobjects.id = sysconstraints.constid and
sysconstraints.constid = syscomments.id and sysconstraints.colid = 0) b on
a.id = b.id
SQL檢視CHECK約束資訊
以下兩個語句均基於系統表sysobjects syscomments和系統檢視sysconstraints,查詢結果中包括表id 表名 列id 列名 check約束id check約束名 check約束status值以及check約束的內容,tccview為table column check vi...
SQL檢視CHECK約束資訊
以下兩個語句均基於系統表sysobjects syscomments和系統檢視sysconstraints,查詢結果中包括表id 表名 列id 列名 check約束id check約束名 check約束status值以及check約束的內容,tccview為table column check vi...
MySQL檢查約束(CHECK)
mysql 檢查約束 check 可以通過 create table 或 alter table 語句實現,根據使用者實際的完整性要求來定義。它可以分別對列或表實施 check 約束。檢查約束使用check關鍵字,具體的語法格式如下 check 表示式 其中 表示式 指的就是 sql 表示式,用於指...