2010-12-15 62 views

回答

4

取决于它的SQL Server版本使用的是:

2000年,使用的syscolumns:

select object_name(select object_name(id) 
from syscolumns 
where name = 'ID' 

对于2005+使用SYS.COLUMNS :

select object_name(object_id) 
from sys.columns 
where name = 'ID' 

你的object_name()函数的se取消了在对象表上需要内部联接的需要。

1

是,您可以:

select o.type, o.name from sys.columns c 
    join sys.objects o on c.object_id = o.object_id 
where c.name = @col_to_find 
+0

谢谢 - 我现在就去试试吧... – Ben 2010-12-15 17:30:59

3

如果是SQL Server 2005或2008,则可以使用INFORMATION_SCHEMA视图。这样

http://msdn.microsoft.com/en-us/library/ms186778.aspx

SQL语句会发现你在找什么:

select * from information_schema.parameters where parameter_name like '%field%' 
select * from information_schema.columns where column_name like '%field%' 
相关问题