query db name and table name by the column name in db server
2008-11-28 10:21
525 查看
Code
declare
@sql varchar(max),
@column_name varchar(200);
set @sql = '';
set @column_name = 'BlackOutFromDate' --table name
select @sql = @sql + 'union all select ''' + name + ''' as DB_Name ,object_name(object_id) as table_name from [' + name + '].sys.columns where name = '''+ @column_name + ''' '
from sys.sysdatabases where sid <> 0x01 and version <> 0;
set @sql = right(@sql,len(@sql)-9);
exec(@sql);
declare
@sql varchar(max),
@column_name varchar(200);
set @sql = '';
set @column_name = 'BlackOutFromDate' --table name
select @sql = @sql + 'union all select ''' + name + ''' as DB_Name ,object_name(object_id) as table_name from [' + name + '].sys.columns where name = '''+ @column_name + ''' '
from sys.sysdatabases where sid <> 0x01 and version <> 0;
set @sql = right(@sql,len(@sql)-9);
exec(@sql);
相关文章推荐
- sql server query to get the list of column name in a table
- sql: Query to Display Foreign Key Relationships and Name of the Constraint for Each Table in Database
- An explicit value for the identity column in table can only be specified when a column list is used and IDENTITY_INSERT is ON
- rror Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnec
- DB Query Analyzer 5.03 is distributed, EXCEL table name will be enclosed in square bracket
- mysql query to find the maximum 3 values from a column and group by on other column
- DB Query Analyzer 5.03 is distributed, EXCEL table name will be enclosed in square bracket
- 82.Examine the data in the CUST_NAME column of the CUSTOMERS table.
- The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.
- 【MySQL笔记】解除输入的安全模式,Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect.
- DB Query Analyzer 5.03 is distributed, EXCEL table name will be enclosed in square bracket
- The table name must be enclosed in double quotation marks or sqare bracket while accessing EXCEL by
- 83.Examine the data in the CUST_NAME column of the CUSTOMERS table.
- The table name must be enclosed in double quotation marks or sqare bracket while accessing EXCEL by
- The table name must be enclosed in double quotation marks or sqare bracket while accessing EXCEL by
- MySQL错误:Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL easonjim
- Mysql解决SELECT list is not in GROUP BY clause and contains nonaggregated column 问题
- ORA-01688:unable to extend table name。name partition NAME by NUM in tablespace NAME
- Error response from daemon: Conflict. The container name "/mysql" is already in use by container
- The Difference of Class.forName()、Class.forName().newInstance() and New in Java