Dzwebs.Net

撰写电脑技术杂文十余年

查询返回表名与字段名称

Admin | 2007-10-11 13:33:57 | 被阅次数 | 9382

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

select name  from syscolumns where id=object_id('表名')

 读取数据库名及表与表中的字段
选择一个服务器后,列出该服务器中所有数据库:
Select * from Master.dbo.sysdatabases;

选择一个库后读该库中表:
select * from dbo.sysobjects where OBJECTPROPERTY(id, N'IsUserTable') = 1;

列出表中的字段:
select c.name as ColumnName, c.colorder as ColumnOrder, c.xtype as DataType, typ.name as DataTypeName, c.Length, c.isnullable from dbo.syscolumns c inner join dbo.sysobjects t
 on c.id = t.id
 inner join dbo.systypes typ on typ.xtype = c.xtype
 where OBJECTPROPERTY(t.id, N'IsUserTable') = 1
 and t.name='" + tableName + "' order by c.colorder";


 


网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231