获得SQL数据库信息的代码

前端之家收集整理的这篇文章主要介绍了获得SQL数据库信息的代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="5634" class="copybut" id="copybut5634" onclick="doCopy('code5634')"> 代码如下:

<div class="codebody" id="code5634">
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'表名') --获得表里的所有字段

--获取表字段名、类型、递增、描述
<div class="codetitle"><a style="CURSOR: pointer" data="97348" class="copybut" id="copybut97348" onclick="doCopy('code97348')"> 代码如下:
<div class="codebody" id="code97348">
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 = '表名'

原文链接:https://www.f2er.com/mssql/64116.html

猜你在找的MsSQL相关文章