select OBJECT_NAME(object_id) from sys.all_columns where name='字段名'
DECLARE @ColName VARCHAR(MAX)--如查表中包含'ID'字段的所有表 SET @ColName = 'ID'SELECT a.name 表名 , b.name 列名 FROM sysobjects a , syscolumns b WHERE a.id = b.id AND b.name = @ColName AND a.type = 'U'
--用到系统表来查询 declare @id int select @id = id from syscolumns where [name] = '字段名'select name from sysobjects where id = @id and xtype = 'U'
select* from syscolumns where cloumn_name = '字段名'
SELECT a.name 表名 FROM sysobjects a JION syscolumns b ON a.id = b.id AND b.name = '字段名' AND a.type = 'U'
谢谢。。这句对我很有启发。。对两张表的结构有了一个了解。但这个语句有问题,如果我一个字段在多个表名中有。那怎么办。。依据你的思维。select a.name from sysobjects a join syscolumns b on a.id=b.id where b.name='字段名'
select name from sysobjects where id in (select id from syscolumns where name='字段名') and xtype='u'
select table_name from information_schema.columns where column_name='字段名' ;
DECLARE @ColName VARCHAR(MAX)--如查表中包含'ID'字段的所有表
SET @ColName = 'ID'SELECT a.name 表名 ,
b.name 列名
FROM sysobjects a ,
syscolumns b
WHERE a.id = b.id
AND b.name = @ColName
AND a.type = 'U'
--用到系统表来查询
declare @id int
select @id = id from syscolumns where [name] = '字段名'select name from sysobjects where id = @id and xtype = 'U'
select* from syscolumns where cloumn_name = '字段名'
FROM sysobjects a
JION syscolumns b
ON a.id = b.id
AND b.name = '字段名'
AND a.type = 'U'
谢谢。。这句对我很有启发。。对两张表的结构有了一个了解。但这个语句有问题,如果我一个字段在多个表名中有。那怎么办。。依据你的思维。select a.name from sysobjects a join syscolumns b on a.id=b.id
where b.name='字段名'
(select id from syscolumns where name='字段名') and xtype='u'