--查询数据库中的所有表
select table_name from 数据库名.INFORMATION_SCHEMA.TABLES Where TABLE_TYPE='BASE TABLE'
--查询表字段
use northwind --数据库名
go
Select dbo.sysobjects.name as Table_name,
dbo.syscolumns.name AS Column_name FROM dbo.syscolumns INNER JOIN dbo.sysobjects ON dbo.syscolumns.id = dbo.sysobjects.id
Where (dbo.sysobjects.xtype = 'u') AND (NOT (dbo.sysobjects.name LIKE 'dtproperties'))
go
--查询表字段,数据类型,数据长度
use northwind --数据库名
go
select t.name as tablename,c.name as columnname,ty.name as typename,c.max_length as typelength
from sys.columns c inner join sys.tables t on t.object_id=c.object_id inner join sys.types ty
on ty.system_type_id=c.system_type_id order by t.name,c.column_id for xml auto
go
本文出自 “糖炒栗子” 博客,请务必保留此出处http://tangchaolizi.blog.51cto.com/3126463/1175946