以下兩個語句均基於系統表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...
SQL 2005 CHECK約束和規則區別
一 約束 約束定義關於列中允許值的規則,是強制完整性的標準機制。使用約束優先於使用觸發器 規則和預設值。查詢優化器也使用約束定義生成高效能的查詢執行計劃。sql server 2005支援五類約束 1.not null指定不接受null值的列。2.check 約束對可以放入列中的值進行限制,以強制執...
MySQL的SQL中CHECK約束的支援問題
後記 最近在建立mysql表的時候,對於建表要求給的check約束不是很清楚,就上網查了一下mysql的check約束。結果網上的回答通過例項告訴我mysql能接收check,但接收後不解析,也就是說沒用。但是自己親手試過之後發現自己的mysql確實能實現check的約束,這一點就讓我很迷惑。che...
SQL儲存過程相關資訊檢視
1 檢視所有儲存過程與函式 exec sp stored procedures 或者select from dbo.sysobjects where objectproperty id,n isprocedure 1 order by name 2 檢視儲存過程的內容 select text fro...