取sqlserver 表结构
作者:admin 日期:2009-05-15
create table ta(id int,name varchar(30),date datetime)
create table tb(id int,name varchar(30))
select a.name '表名',b.name '字段名',c.name '类型',b.length '长度' from sysobjects a,syscolumns b,systypes c
where a.id=b.id and a.xtype='u' and b.xtype=c.xtype order by a.name
表名 字段名 类型 长度
ta id int 4
ta name varchar 30
ta date datetime 8
tb id int 4
tb name varchar 30
------------------------------------------------------------------------------------------------------
Select
(case when a.colorder=1 then d.name else '' end) N'表名',
a.colorder N'字段序号',
a.name N'字段名',
(case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) N'标识',
(case when (Select count(*)
FROM sysobjects
Where (name in
(Select name
FROM sysindexes
Where (id = a.id) AND (indid in
(Select indid
FROM sysindexkeys
Where (id = a.id) AND (colid in
(Select colid
FROM syscolumns
Where (id = a.id) AND (name = a.name))))))) AND
(xtype = 'PK'))>0 then '√' else '' end) N'主键',
b.name N'类型',
a.length N'占用字节数',
COLUMNPROPERTY(a.id,a.name,'PRECISION') as N'长度',
isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as N'小数位数',
(case when a.isnullable=1 then '√'else '' end) N'允许空',
isnull(e.text,'') N'默认值',
isnull(g.[value],'') AS N'字段说明'
--into ##tx
FROM syscolumns a left join systypes b
on a.xtype=b.xusertype
inner join sysobjects d
on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
left join syscomments e
on a.cdefault=e.id
left join sysproperties g
on a.id=g.id AND a.colid = g.smallid
order by object_name(a.id),a.colorder
------------------------------------------------------------------------------------------------
select * from sysobjects where xtype='u' --讀取所有用戶表
select * from syscolumns --讀取所有columns
create table tb(id int,name varchar(30))
select a.name '表名',b.name '字段名',c.name '类型',b.length '长度' from sysobjects a,syscolumns b,systypes c
where a.id=b.id and a.xtype='u' and b.xtype=c.xtype order by a.name
表名 字段名 类型 长度
ta id int 4
ta name varchar 30
ta date datetime 8
tb id int 4
tb name varchar 30
------------------------------------------------------------------------------------------------------
Select
(case when a.colorder=1 then d.name else '' end) N'表名',
a.colorder N'字段序号',
a.name N'字段名',
(case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) N'标识',
(case when (Select count(*)
FROM sysobjects
Where (name in
(Select name
FROM sysindexes
Where (id = a.id) AND (indid in
(Select indid
FROM sysindexkeys
Where (id = a.id) AND (colid in
(Select colid
FROM syscolumns
Where (id = a.id) AND (name = a.name))))))) AND
(xtype = 'PK'))>0 then '√' else '' end) N'主键',
b.name N'类型',
a.length N'占用字节数',
COLUMNPROPERTY(a.id,a.name,'PRECISION') as N'长度',
isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as N'小数位数',
(case when a.isnullable=1 then '√'else '' end) N'允许空',
isnull(e.text,'') N'默认值',
isnull(g.[value],'') AS N'字段说明'
--into ##tx
FROM syscolumns a left join systypes b
on a.xtype=b.xusertype
inner join sysobjects d
on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
left join syscomments e
on a.cdefault=e.id
left join sysproperties g
on a.id=g.id AND a.colid = g.smallid
order by object_name(a.id),a.colorder
------------------------------------------------------------------------------------------------
select * from sysobjects where xtype='u' --讀取所有用戶表
select * from syscolumns --讀取所有columns
[本日志由 admin 于 2009-05-15 03:44 PM 编辑]
文章来自: 本站原创
引用通告地址: http://www.is21.cn/trackback.asp?tbID=655
Tags:
文章来自: 本站原创
引用通告地址: http://www.is21.cn/trackback.asp?tbID=655
Tags:
评论: 0 | 引用: 0 | 查看次数: 1654
发表评论
你没有权限发表留言!