您好,登錄后才能下訂單哦!
SQL Server中Table字典數(shù)據(jù)的查詢SQL示例代碼怎么寫(xiě),相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。
前言
數(shù)據(jù)庫(kù)包含4類數(shù)據(jù):
1.用戶數(shù)據(jù)
2.元數(shù)據(jù)
3.索引
4.應(yīng)用元數(shù)據(jù)
其中,元數(shù)據(jù)也叫數(shù)據(jù)字典,定義如下:
下面這篇文章就來(lái)給大家分享一個(gè)關(guān)于查詢SQL Server Table 結(jié)構(gòu)的SQL 語(yǔ)句。
T-SQL 如下:
SELECT (case when a.colorder=1 then d.name else '' end) 表名, a.colorder 字段序號(hào), a.name 字段名, (case when a.colorder=1 then isnull(f.value,'') else '' end) 表說(shuō)明, (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '1'else '0' end)標(biāo)識(shí), (case when (SELECT count(*) FROM sysobjectsWHERE (name in (SELECT name FROM sysindexesWHERE (id = a.id) AND (indid in(SELECT indid FROM sysindexkeysWHERE (id = a.id) AND (colid in(SELECT colid FROM syscolumns WHERE (id = a.id) AND (name = a.name))))))) AND (xtype = 'PK'))>0 then '1' else '0' end) 主鍵, b.name 類型, a.length 占用字節(jié)數(shù), COLUMNPROPERTY(a.id,a.name,'PRECISION') as 長(zhǎng)度, isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小數(shù)位數(shù), (case whena.isnullable=1 then '1'else '0' end) 允許空, isnull(e.text,'') 默認(rèn)值, isnull(g.[value], ' ') AS [說(shuō)明]FROM syscolumns aleft join systypes b on a.xtype=b.xusertypeinner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'left join syscomments e on a.cdefault=e.idleft join sys.extended_properties g on a.id=g.major_id AND a.colid=g.minor_idleft join sys.extended_properties f on d.id=f.major_id and f.minor_id=0--where b.name is not nullWHERE d.name='DBA_Server' --如果只查詢指定表,加上此條件,此案例為表DBA_Serverorder by a.id,a.colorder
看完上述內(nèi)容,你們掌握SQL Server中Table字典數(shù)據(jù)的查詢SQL示例代碼怎么寫(xiě)的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。