SELECT NAME FROM SYSCOLUMNS WHERE ID=OBJECT_ID('TB')
select name from syscolumns where id=object_id('tableName')
SELECT NAME FROM SYSCOLUMNS WHERE ID=OBJECT_ID('TB')
use cfms Select col.[name] as '字段名', col.[length]as '长度' , type.[name] as '类型' , pro.value as '描述' From syscolumns as col Left Join systypes as type on col.xtype = type.xtype Left Join sysProperties as pro on col.id = pro.id and col.colid = pro.smallid where col.id = (Select id From Sysobjects Where name = '表名称')
declare @字段名 varchar(1000) SELECT @字段名=isnull(@字段名+',','')+NAME FROM SYSCOLUMNS WHERE ID=OBJECT_ID('表名') print @字段名
SELECT NAME FROM SYSCOLUMNS WHERE ID=OBJECT_ID('TB')
列出数据库里所有的表名 select name from sysobjects where type='U' 列出表里的所有的列 select name from syscolumns where id=object_id('TableName')
用sql可以同时得到字段名和字段吗?
用sql可以同时得到字段名和字段吗? 这句话的字段怎么理解?
如果是指定一个表想查询它的字段,则 sp_help 'tbname' 其实这些信息可以从sysobjects和syscolumns中查询。 select * from sysobjects可以查询出数据库中所有的表,加上条件xtype='U'则只查询出用户表。 select * from syscolumns可以查询中数据库在所有的字段。 如果要查询一个表中的所有字段,或者查询包含某一字段的所有表, 可以用子查询来实现。
select name from sys.all_columns where object_id=object_id('table_name')
select OBJECT_NAME ( a.object_id ) from sys.columns a ,sys.objects b where a.object_id = b.object_id and b.type = 'U'
use cfms
Select
col.[name] as '字段名',
col.[length]as '长度' ,
type.[name] as '类型' ,
pro.value as '描述'
From syscolumns as col
Left Join systypes as type on col.xtype = type.xtype
Left Join sysProperties as pro on col.id = pro.id and col.colid = pro.smallid
where col.id = (Select id From Sysobjects Where name = '表名称')
declare @字段名 varchar(1000)
SELECT @字段名=isnull(@字段名+',','')+NAME FROM SYSCOLUMNS WHERE ID=OBJECT_ID('表名')
print @字段名
select name from sysobjects where type='U'
列出表里的所有的列
select name from syscolumns where id=object_id('TableName')
sp_help 'tbname'
其实这些信息可以从sysobjects和syscolumns中查询。
select * from sysobjects可以查询出数据库中所有的表,加上条件xtype='U'则只查询出用户表。
select * from syscolumns可以查询中数据库在所有的字段。
如果要查询一个表中的所有字段,或者查询包含某一字段的所有表,
可以用子查询来实现。
select name from sys.all_columns where object_id=object_id('table_name')
from sys.columns a
,sys.objects b
where a.object_id = b.object_id
and b.type = 'U'