select * from sysobjects --查询所有信息 SELECT Name FROM Master..SysDatabases ORDER BY Name --查询所有数据库名字 SELECT name FROM sysobjects WHERE xtype='U' --查询数据库表(先引用数据库[use]) select * from sys.tables --查询数据库表名 select * from Dictionary -- 查询表中数据
select * from sys.columns where object_id=object_id('Dictionary') --查询所有列名的信息
SELECT * FROM sys.extended_properties WHERE major_id = OBJECT_ID ('Dictionary' ) --查询表中列的说明
select name,system_type_id,user_type_id,max_length from sys.columns where object_id=object_id('BalanDetail') --查询表中字段的信息
select name,replace(system_type_id,'56','十'),replace(user_type_id,'56','十'),max_length from sys.columns where object_id=object_id('BalanDetail') --查询所有替换后的信息
select name, CASE system_type_id WHEN '56' THEN 'int' WHEN '231' THEN 'nvarchar' WHEN '104' THEN 'bit' WHEN '61' THEN 'datetime' END, CASE user_type_id WHEN '56' THEN 'int' WHEN '231' THEN 'nvarchar' WHEN '104' THEN 'bit' WHEN '61' THEN 'datetime' END,replace(max_length,'-1','max') ,[precision] from sys.columns where object_id=object_id('xxx') --查询所有列名的信息
--56=int , 231 = nvarchar,104 = bit,61 = datetime , -1 = max ---scale 小数位数 -- precision 有效数字位数 select name, null, CASE system_type_id WHEN '56' THEN 'int' WHEN '231' THEN 'nvarchar' WHEN '104' THEN 'bit' WHEN '61' THEN 'datetime' END as 类型, replace(max_length,'-1','max') as 长度 ,[precision],scale,CASE user_type_id WHEN '56' THEN 'int' WHEN '231' THEN 'nvarchar' WHEN '104' THEN 'bit' WHEN '61' THEN 'datetime' END as 类型 from sys.columns where object_id=object_id('BalanDetail') --查询所有列名的信息