曹永思

导航

获取数据库中的所有用户表、取数据表的描述信息包括描述说明

--获取所有数据库名
Select Name FROM Master..SysDatabases ORDER BY Name

--获取指定数据库的所有表(DatabaseName 替换成指定库名即可)
use DatabaseName select table_name  from information_schema.columns group by table_name

--获取数据库中所有的用户表
 Select Name FROM SysObjects Where XType='U' orDER BY Name

--获取数据库中数据表所有字段 (将tbName替换成你的表名即可)
select    a.*   from   syscolumns   a,   sysobjects   b   where   a.id=b.id   and   b.name= 'ContentInfo'

 //code by:博客园-曹永思-在线起名

--获取数据表的详细信息  (将tbName替换成你的表名即可)
SELECT CASE WHEN EXISTS (SELECT 1 FROM sysobjects WHERE xtype='PK' AND parent_obj = a.id 
AND name IN (SELECT name FROM sysindexes WHERE indid IN (SELECT indid FROM sysindexkeys
 WHERE id = a.id AND colid = a.colid))) THEN '1' ELSE '0' END AS 'key', 
CASE WHEN COLUMNPROPERTY(a.id, a.name, 'IsIdentity') = 1 THEN '1' ELSE '0' END AS 'identity', a.name AS ColName,
 c.name AS TypeName, a.length AS 'byte', 
COLUMNPROPERTY(a.id, a.name, 'PRECISION') AS 'length',
 a.xscale, a.isnullable, ISNULL(e.text, '') AS 'default', 
ISNULL(p.value, '') AS 'comment'
FROM sys.syscolumns AS a INNER JOIN
                      sys.sysobjects AS b ON a.id = b.id INNER JOIN
                      sys.systypes AS c ON a.xtype = c.xtype LEFT OUTER JOIN
                      sys.syscomments AS e ON a.cdefault = e.id LEFT OUTER JOIN
                      sys.extended_properties AS p ON a.id = p.major_id AND a.colid = p.minor_id
WHERE     (b.name = 'ContentInfo') AND (c.status <> '1')

--获取自增的字段名称(将 tbName 替换成你的表名即可)
select [name] from syscolumns where
id=object_id(N'tbName') and COLUMNPROPERTY(id,name,'IsIdentity')=1

ROW_NUMBER 方式分页语句: select * from(select  ROW_NUMBER()  over(order by AreaId desc) as rn,
 [AreaId],[ParentId],[Sort],[AreaName],[PingYin]
from Aqioo_Area a where 1=1 and PingYin like '%g')  b where rn<(2*6+1) and rn>(2-1)*6 
 
--将表的标识回滚到从0开始
DBCC CHECKIDENT(表名,RESEED,0)

 根据存储过程名称获取存储过程参数的方法:

"SELECT  P.name,'' as value  FROM    sys.parameters P  INNER JOIN sys.objects O ON O.object_id = P.object_id
                                                        WHERE   O.type = 'P' AND P.is_output = 0
                                                                AND O.name = '" + storedProc + "'

 

 

 欢迎转载,转载请注明出处,希望帮到更多人。

 

posted on 2012-08-22 23:11  曹永思  阅读(766)  评论(0编辑  收藏  举报