select name from sys.objects where object_id in(select object_id from sys.columns where name='a')
select a.name from sys.columns a inner join sys.objects where a.id=b.id and b.type='U' 这是所有用户表的所有字段. 表之间的连接,差不多在设计阶段就定下来了,这牵涉到数据库原理,连接主要使用的是所谓 一对多.如果要说清楚的话,得写上半天,建议楼主还是找个基础的书看看吧.
"在ms sql中怎么查询某个字段都存在于哪个表里呢?" select object_name(object_id) 'table_name', name 'column_name' from sys.columns where name='[字段名]'
手误,修改: select a.name from sys.columns a inner join sys.objects on a.id=b.id and b.type='U'
列出表里的所有的列 select name from syscolumns where id=object_id('TableName')
这是所有用户表的所有字段.
表之间的连接,差不多在设计阶段就定下来了,这牵涉到数据库原理,连接主要使用的是所谓 一对多.如果要说清楚的话,得写上半天,建议楼主还是找个基础的书看看吧.
select
object_name(object_id) 'table_name',
name 'column_name'
from sys.columns
where name='[字段名]'
select a.name from sys.columns a inner join sys.objects on a.id=b.id and b.type='U'
select name from syscolumns where id=object_id('TableName')