如何獲取SQL Server所有的資料庫名、表名、欄位名及欄位型別?
阿新 • • 發佈:2019-01-04
解決方案
– 獲取所有資料庫名
select name from master..sysdatabases– 獲取所有表名
select name from YDK..SysObjects where XType=’U’ order by name– 獲取欄位名
select * from SysColumns where id=Object_id(‘YDS_XMXX’) order by name– 獲取欄位型別
select column_name,data_type from information_schema.columns
where table_name=’YDS_XMXX’ and column_name=’XMMC’– 獲取表主鍵
Select name FROM SysColumns Where id=Object_Id(‘表名’) and colid=(select top 1 keyno from sysindexkeys where id=Object_Id(‘表名’))