Query to Find Column Name From All Tables
Posted by Ramani Sandeep on April 7, 2009
Question : How many tables in your database have column name like ‘CategoryID’ ?
Solution :
SELECT t.name AS table_name, SCHEMA_NAME(schema_id) AS schema_name, c.name AS column_name FROM sys.tables AS t INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID WHERE c.name LIKE ‘%CategoryID%’ ORDER BY schema_name, table_name;
Question : How to find all the column name from your database ?
Solution :
SELECT t.name AS table_name, SCHEMA_NAME(schema_id) AS schema_name, c.name AS column_name FROM sys.tables AS t INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID ORDER BY schema_name, table_name;
Hope this will help
Jay Ganesh
Advertisement
Martin said
When and where were you born?
Krishna Patel said
Hi Mr.Sandeep,
how to wright under give Sql Query in Linq ???
select coalesce(Clientname,’,') + ‘-’ + coalesce(clienturl,’,') as HostHeaders, ClientName, ClientURL, Id from Client
Ramani Sandeep said
Hi Krishna,
The ?? operator is called the null-coalescing operator and is used to define a default value for a nullable value types as well as reference types.
your Query can be written as :
Var myClient = from c in DBContext.Client
select new
{
HostHeaders = c.ClientName ?? ‘,’ + ‘-’ + c.ClientUrl ?? ‘,’
};
Please check this out and let me know if you still face any issue.
Regards,
Sandeep