查询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

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

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

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

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

转载于:https://www.cnblogs.com/samsonleung/archive/2008/06/23/1227930.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值