Ever faced a scenario where you want to check whether a column exists in a database table or not? Here is the query for that if you are using the Microsoft SQL Server.
SELECT COUNT(*) FROM SysObjects S INNER JOIN SysColumns C ON S.ID=C.ID WHERE ObjectProperty(S.ID,'IsUserTable')=1 AND S.Name='TableName' AND C.Name='ColumnName'
Replace ‘TableName’ and ‘ColumnName’ values in the above query with your own values of table name and column name which you are searching for.
The query will return 0 if the column is not found in that table, and will return 1 if the column is found.






No Comments Yet - be the First!