主頁 > 知識庫 > 獲取SQL Server表字段的各種屬性實例代碼

獲取SQL Server表字段的各種屬性實例代碼

熱門標簽:美團地圖標注商戶認證注冊 慶陽地圖標注 咸陽電腦外呼系統(tǒng)運營商 榕城市地圖標注 承德地圖標注公司名需要花錢嗎 怎么給高德做地圖標注 浙江穩(wěn)定外呼系統(tǒng)供應商 電銷外呼系統(tǒng)軟件功能 北京400電話辦理多少錢

復制代碼 代碼如下:

-- SQL Server 2000
SELECT a.name AS 字段名, CASE WHEN EXISTS
(SELECT 1
FROM sysobjects
WHERE xtype = 'PK' AND parent_obj = a.id AND name IN
(SELECT name
FROM sysindexes
WHERE indid IN
(SELECT indid
FROM sysindexkeys
WHERE id = a.id AND colid = a.colid)))
THEN '1' ELSE '0' END AS 主鍵, CASE WHEN COLUMNPROPERTY(a.id, a.name,
'IsIdentity') = 1 THEN '1' ELSE '0' END AS 標識, b.name AS 類型,
a.length AS 占用字節(jié)數(shù), COLUMNPROPERTY(a.id, a.name, 'PRECISION') AS 長度,
a.xscale AS 小數(shù), a.isnullable AS 可空, ISNULL(e.text, '') AS 默認值, ISNULL(g.[value],
'') AS 字段說明
FROM syscolumns a LEFT OUTER JOIN
systypes b ON a.xusertype = b.xusertype INNER JOIN
sysobjects d ON a.id = d.id AND d.xtype = 'U' AND
d.name > 'dtproperties' LEFT OUTER JOIN
syscomments e ON a.cdefault = e.id LEFT OUTER JOIN
sysproperties g ON a.id = g.id AND a.colid = g.smallid LEFT OUTER JOIN
sysproperties f ON d.id = f.id AND f.smallid = 0
WHERE (d.name = '表名稱')
--2。SQL SERVER 2005
SELECT CASE WHEN EXISTS
(SELECT 1
FROM sysobjects
WHERE xtype = 'PK' AND parent_obj = a.id AND name IN
(SELECT name
FROM sysindexes
WHERE indid IN
(SELECT indid
FROM sysindexkeys
WHERE id = a.id AND colid = a.colid))) THEN '1' ELSE '0' END AS 'key', CASE WHEN COLUMNPROPERTY(a.id, a.name,
'IsIdentity') = 1 THEN '1' ELSE '0' END AS 'identity', a.name AS ColName, c.name AS TypeName, a.length AS 'byte', COLUMNPROPERTY(a.id, a.name,
'PRECISION') AS 'length', a.xscale, a.isnullable, ISNULL(e.text, '') AS 'default', ISNULL(p.value, '') AS 'comment'
FROM sys.syscolumns AS a INNER JOIN
sys.sysobjects AS b ON a.id = b.id INNER JOIN
sys.systypes AS c ON a.xtype = c.xtype LEFT OUTER JOIN
sys.syscomments AS e ON a.cdefault = e.id LEFT OUTER JOIN
sys.extended_properties AS p ON a.id = p.major_id AND a.colid = p.minor_id
WHERE (b.name = 'keyfactory') AND (c.status > '1')
--b.name = 'Keyfactory','Keyfactory'為你想要查找的數(shù)據(jù)表。

--2、SQL SERVER 2005
SELECT CASE WHEN EXISTS
(SELECT 1
FROM sysobjects
WHERE xtype = 'PK' AND parent_obj = a.id AND name IN
(SELECT name
FROM sysindexes
WHERE indid IN
(SELECT indid
FROM sysindexkeys
WHERE id = a.id AND colid = a.colid))) THEN '1' ELSE '0' END AS 'key', CASE WHEN COLUMNPROPERTY(a.id, a.name,
'IsIdentity') = 1 THEN '1' ELSE '0' END AS 'identity', a.name AS ColName, c.name AS TypeName, a.length AS 'byte', COLUMNPROPERTY(a.id, a.name,
'PRECISION') AS 'length', a.xscale, a.isnullable, ISNULL(e.text, '') AS 'default', ISNULL(p.value, '') AS 'comment'
FROM sys.syscolumns AS a INNER JOIN
sys.sysobjects AS b ON a.id = b.id INNER JOIN
sys.systypes AS c ON a.xtype = c.xtype LEFT OUTER JOIN
sys.syscomments AS e ON a.cdefault = e.id LEFT OUTER JOIN
sys.extended_properties AS p ON a.id = p.major_id AND a.colid = p.minor_id
WHERE (b.name = 'keyfactory') AND (c.status > '1')
--b.name = 'Keyfactory','Keyfactory'為你想要查找的數(shù)據(jù)表。

標簽:江蘇 拉薩 昭通 重慶 呼和浩特 貴州 新鄉(xiāng) 上海

巨人網(wǎng)絡通訊聲明:本文標題《獲取SQL Server表字段的各種屬性實例代碼》,本文關鍵詞  獲取,SQL,Server,表,字段,的,;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《獲取SQL Server表字段的各種屬性實例代碼》相關的同類信息!
  • 本頁收集關于獲取SQL Server表字段的各種屬性實例代碼的相關信息資訊供網(wǎng)民參考!
  • 推薦文章