查询SQLServer数据库信息的几条语句

摘自:http://hi.baidu.com/chinamis/blog/item/1a7423fa714a109258ee9071.html(迷茫深圳博客)
1、求某一表的字段名称,类型、长度:
select b.name as fieldname,c.name as typename,b.length as fieldlen 
from sysobjects a,syscolumns b,systypes c
where a.id=b.id and b.xtype=c.xtype and a.name='表名' 
order by b.colid

1select  column_name,data_type ,character_maximum_length
2from information_schema.columns
3where table_name = '表名'
4order by ordinal_position 

2、N到M条记录(要有主索引ID):
1Select Top M-* 
2From 表 Where ID in
3   (Select Top M ID From 表)
4 Order by ID Desc

3、查询用户创建的所有数据库
1select * from master..sysdatabases D 
2where sid not in
3(select sid from master..syslogins where name='sa')

4、查看当前数据库中所有存储过程
1select name as 存储过程名称
2from sysobjects
3where xtype='P'--视图为'V',触发器'TR',用户表为'U',系统表为'S'

原文地址:https://www.cnblogs.com/samsonleung/p/1227930.html