sql擷取表結構

來源:互聯網
上載者:User

標籤:for   dtp   orm   else   char   sql   extend   column   mat   

SELECT a.name 欄位名,            (case when COLUMNPROPERTY( a.id,a.name,‘IsIdentity‘)=1 then 1 ELSE 0 end) 標識,             (case when (SELECT count(*) FROM dbo.sysobjects              WHERE (name in (SELECT name FROM dbo.sysindexes              WHERE (id = a.id) AND (indid in              (SELECT indid FROM dbo.sysindexkeys              WHERE (id = a.id) AND (colid in              (SELECT colid FROM dbo.syscolumns WHERE (id = a.id) AND (name = a.name)))))))              AND (xtype = ‘PK‘))>0 then 1 else 0 end) 主鍵,b.name 類型,            h.CHARACTER_MAXIMUM_LENGTH as 長度,h.NUMERIC_PRECISION as 數字長度,            isnull(h.NUMERIC_SCALE,0) as 小數位元,(case when a.isnullable=1 then 1 ELSE 0 end) 允許空,              isnull(e.text,‘‘) 預設值,isnull(g.[value], ‘ ‘) AS [說明]            FROM  dbo.syscolumns a             left join dbo.systypes b on a.xtype=b.xusertype              inner join dbo.sysobjects d on a.id=d.id and d.xtype=‘U‘ and d.name<>‘dtproperties‘             left join dbo.syscomments e on a.cdefault=e.id              left join sys.extended_properties g on a.id=g.major_id AND a.colid=g.minor_id            left join sys.extended_properties f on d.id=f.class and f.minor_id=0            LEFT JOIN information_schema.COLUMNS h ON h.TABLE_NAME = d.name AND h.COLUMN_NAME = a.name            --where b.name is not null            WHERE d.name=‘StockInfo‘ --如果只查詢指定表,加上此條件            order by a.id,a.colorder

 

sql擷取表結構

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.