取得SQL數據庫信息的代碼。本站提示廣大學習愛好者:(取得SQL數據庫信息的代碼)文章只能為提供參考,不一定能成為您想要的結果。以下是取得SQL數據庫信息的代碼正文
SELECT Name FROM Master..SysDatabases ORDER BY Name --取得一切數據庫
SELECT Name FROM [數據庫名]..SysObjects Where XType='U' ORDER BY Name --取得數據庫下的一切表
select name from syscolumns where id=object_id(N'表名') --取得內外的一切字段
--獲得表字段名、類型、遞增、描寫
select syscolumns.name as 字段,syscolumns.isnullable as 能否為空,systypes.name as SQL類型,
ISNULL(sys.identity_columns.is_identity,0) as 遞增,
ISNULL(sys.extended_properties.value,'') as 描寫 from sysobjects
join syscolumns on sysobjects.id = syscolumns.id
join systypes on syscolumns.xusertype = systypes.xusertype
left join sys.identity_columns on sys.identity_columns.object_id = syscolumns.id
and sys.identity_columns.column_id = syscolumns.colid
left join sys.extended_properties on sys.extended_properties.major_id = syscolumns.id
and sys.extended_properties.minor_id = syscolumns.colid
where sysobjects.name = '表名'