使用于SQL SERVER 2008
----查询所有数据库名

1 SELECT Name FROM Master..SysDatabases ORDER BY Name

----查询某数据库中的所有表名

1 SELECT Name FROM 数据库名..SysObjects Where XType='U' ORDER BY Name

----查询数据表的字段信息

 1 select 
 2 a.name as FieldName,  -- 字段名
 3 a.isnullable,         -- 是否可为空
 4 b.Value as FieldDesc, -- 字段说明
 5 c.name as FieldType,  -- 数据类型
 6 COLUMNPROPERTY(a.id,a.name,'IsIdentity') as isidentity,  --是否标识列
 7 PK=case when exists(SELECT 1 FROM sysobjects where xtype='PK' and parent_obj=a.id and name in (
 8 SELECT name FROM sysindexes WHERE indid in(
 9 SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid
10 ))) then 'true' else 'false' end  --是否主键
11 from SysColumns a left join
12  sysproperties b on a.id=b.id and a.colid=b.smallid left join systypes c on a.xusertype=c.xusertype
13  where a.id=Object_Id('数据表名')

 

相关文章:

  • 2022-12-23
  • 2021-05-28
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
  • 2022-03-09
猜你喜欢
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2021-07-18
  • 2022-12-23
相关资源
相似解决方案