关于SQL系统对象

1.获取所有用户信息:

   SELECT * FROM Sysusers

2.获取所有数据库信息:

  select  *from  master..sysdatabases

3.获取当前数据库下的所以表信息

  select   *   from   dbo.sysobjects

 where  xtype='U'

xtype='U':表示所有用户表;
xtype='S':表示所有系统表;

4.获取指定表名下的所以字段信息

 select  * from dbo.syscolumns where  id=Object_Id('verbal')

 等价于:

select  *from  syscolumns  where  id =(select  id from sysobjects where  xtype='U' and  name ='verbal')

5.获取数据库所以类型:
 select  * from dbo.systypes

6.获取字段的类型

select a.name as [column],b.name as type from syscolumns a,systypes b where a.id=object_id('verbal') and a.xtype=b.xtype
7.获取表结构:

select column_name,data_type,character_maximum_length,* from information_schema.columns where table_name = 'verbal'

8.获取数据库索引

select * from  sysindexes where id=Object_Id('verbal')

ID(如果 indid= 0 255)。否则为索引所属表的 ID
9.
 

 

原文地址:https://www.cnblogs.com/linsu/p/2457473.html