您好,登錄后才能下訂單哦!
本篇內容主要講解“如何利用三個SQL視圖查出所有SQLServer數據庫字典”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“如何利用三個SQL視圖查出所有SQLServer數據庫字典”吧!
1.SQLServer數據庫字典--表結構.sql
SELECTTOP100PERCENT--a.id,CASEWHENa.colorder=1THENd.nameELSE''ENDAS表名,CASEWHENa.colorder=1THENisnull(f.value,'')ELSE''ENDAS表說明,a.colorderAS字段序號,a.nameAS字段名,CASEWHENCOLUMNPROPERTY(a.id,a.name,'IsIdentity')=1THEN'√'ELSE''ENDAS標識,CASEWHENEXISTS(SELECT1FROMdbo.sysindexessiINNERJOINdbo.sysindexkeyssikONsi.id=sik.idANDsi.indid=sik.indidINNERJOINdbo.syscolumnsscONsc.id=sik.idANDsc.colid=sik.colidINNERJOINdbo.sysobjectssoONso.name=si.nameANDso.xtype='PK'WHEREsc.id=a.idANDsc.colid=a.colid)THEN'√'ELSE''ENDAS主鍵,b.nameAS類型,a.lengthAS長度,COLUMNPROPERTY(a.id,a.name,'PRECISION')AS精度,ISNULL(COLUMNPROPERTY(a.id,a.name,'Scale'),0)AS小數位數,CASEWHENa.isnullable=1THEN'√'ELSE''ENDAS允許空,ISNULL(e.text,'')AS默認值,ISNULL(g.[value],'')AS字段說明,d.crdateAS創建時間,CASEWHENa.colorder=1THENd.refdateELSENULLENDAS更改時間FROMdbo.syscolumnsaLEFTOUTERJOINdbo.systypesbONa.xtype=b.xusertypeINNERJOINdbo.sysobjectsdONa.id=d.idANDd.xtype='U'ANDd.status>=0LEFTOUTERJOINdbo.syscommentseONa.cdefault=e.idLEFTOUTERJOINdbo.syspropertiesgONa.id=g.idANDa.colid=g.smallidANDg.name='MS_Description'LEFTOUTERJOINdbo.syspropertiesfONd.id=f.idANDf.smallid=0ANDf.name='MS_Description'ORDERBYd.name,a.colorderSqlServer2005數據庫字典--表結構.sqlSELECTTOP100PERCENT--a.id,CASEWHENa.colorder=1THENd.nameELSE''ENDAS表名,CASEWHENa.colorder=1THENisnull(f.value,'')ELSE''ENDAS表說明,a.colorderAS字段序號,a.nameAS字段名,CASEWHENCOLUMNPROPERTY(a.id,a.name,'IsIdentity')=1THEN'√'ELSE''ENDAS標識,CASEWHENEXISTS(SELECT1FROMdbo.sysindexessiINNERJOINdbo.sysindexkeyssikONsi.id=sik.idANDsi.indid=sik.indidINNERJOINdbo.syscolumnsscONsc.id=sik.idANDsc.colid=sik.colidINNERJOINdbo.sysobjectssoONso.name=si.nameANDso.xtype='PK'WHEREsc.id=a.idANDsc.colid=a.colid)THEN'√'ELSE''ENDAS主鍵,b.nameAS類型,a.lengthAS長度,COLUMNPROPERTY(a.id,a.name,'PRECISION')AS精度,ISNULL(COLUMNPROPERTY(a.id,a.name,'Scale'),0)AS小數位數,CASEWHENa.isnullable=1THEN'√'ELSE''ENDAS允許空,ISNULL(e.text,'')AS默認值,ISNULL(g.[value],'')AS字段說明,d.crdateAS創建時間,CASEWHENa.colorder=1THENd.refdateELSENULLENDAS更改時間FROMdbo.syscolumnsaLEFTOUTERJOINdbo.systypesbONa.xtype=b.xusertypeINNERJOINdbo.sysobjectsdONa.id=d.idANDd.xtype='U'ANDd.status>=0LEFTOUTERJOINdbo.syscommentseONa.cdefault=e.idLEFTOUTERJOINsys.extended_propertiesgONa.id=g.major_idANDa.colid=g.minor_idANDg.name='MS_Description'LEFTOUTERJOINsys.extended_propertiesfONd.id=f.major_idANDf.minor_id=0ANDf.name='MS_Description'ORDERBYd.name,字段序號
怎樣利用三個SQL視圖查出所有SQLServer數據庫字典
2.SQLServer數據庫字典--索引.sql SELECTTOP100PERCENT--a.id,CASEWHENb.keyno=1THENc.nameELSE''ENDAS表名,CASEWHENb.keyno=1THENa.nameELSE''ENDAS索引名稱,d.nameAS列名,b.keynoAS索引順序,CASEindexkey_property(c.id,b.indid,b.keyno,'isdescending')WHEN1THEN'降序'WHEN0THEN'升序'ENDAS排序,CASEWHENp.idISNULLTHEN''ELSE'√'ENDAS主鍵,CASEINDEXPROPERTY(c.id,a.name,'IsClustered')WHEN1THEN'√'WHEN0THEN''ENDAS聚集,CASEINDEXPROPERTY(c.id,a.name,'IsUnique')WHEN1THEN'√'WHEN0THEN''ENDAS唯一,CASEWHENe.idISNULLTHEN''ELSE'√'ENDAS唯一約束,a.OrigFillFactorAS填充因子,c.crdateAS創建時間,c.refdateAS更改時間FROMdbo.sysindexesaINNERJOINdbo.sysindexkeysbONa.id=b.idANDa.indid=b.indidINNERJOINdbo.syscolumnsdONb.id=d.idANDb.colid=d.colidINNERJOINdbo.sysobjectscONa.id=c.idANDc.xtype='U'LEFTOUTERJOINdbo.sysobjectseONe.name=a.nameANDe.xtype='UQ'LEFTOUTERJOINdbo.sysobjectspONp.name=a.nameANDp.xtype='PK'WHERE(OBJECTPROPERTY(a.id,N'IsUserTable')=1)AND(OBJECTPROPERTY(a.id,N'IsMSShipped')=0)AND(INDEXPROPERTY(a.id,a.name,'IsAutoStatistics')=0)ORDERBYc.name,a.name,b.keyno
3.SQLServer數據庫字典--表.視圖.函數.存儲過程.觸發器.主鍵.外鍵.約束.規則.sql
SELECTDISTINCTTOP100PERCENTisnull(p.name,'')AS父對象,o.xtype,CASEo.xtypeWHEN'C'THEN'CHECK約束'WHEN'D'THEN'默認值或DEFAULT約束'WHEN'F'THEN'FOREIGNKEY約束'WHEN'L'THEN'日志'WHEN'FN'THEN'標量函數'WHEN'IF'THEN'內嵌表函數'WHEN'P'THEN'存儲過程'WHEN'PK'THEN'PRIMARYKEY約束'WHEN'RF'THEN'復制篩選存儲過程'WHEN'S'THEN'系統表'WHEN'TF'THEN'表函數'WHEN'TR'THEN'觸發器'WHEN'U'THEN'用戶表'WHEN'UQ'THEN'UNIQUE約束'WHEN'V'THEN'視圖'WHEN'X'THEN'擴展存儲過程'WHEN'R'THEN'規則'ELSENULLENDAS類型,o.nameAS對象名,o.crdateAS創建時間,o.refdateAS更改時間,c.textAS聲明語句,OBJECTPROPERTY(o.id,N'IsMSShipped')FROMdbo.sysobjectsoLeftJOINdbo.sysobjectspONo.parent_obj=p.idLEFTOUTERJOINdbo.syscommentscONo.id=c.idWHERE--(o.xtypeIN('C','D','F','PK','UQ','L','FN','IF','TF','TR','P','R','RF','X','S','U','V'))AND(OBJECTPROPERTY(o.id,N'IsMSShipped')=0)AND(isnull(p.name,'')<>N'dtproperties')。
到此,相信大家對“如何利用三個SQL視圖查出所有SQLServer數據庫字典”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。