Very often you need to use a specific field from sql server database table. The problem is how to find column name in database in any table using tsql
? The answer is use information_schema
and more precisely information_schema.columns
This is easy. Just open new query select the database from the drop down box you want to search and type
where column_name like '%name%'
The sql query above will show you every column that contains value ‘name’. If you have many results you can eliminate them by filtering it using the available columns. Usually table name field can be used to limit the results for instance if you are after name but for an employee you could try:
where column_name like '%name%' and table_name like '%emp%'
Did you find this page useful? +8