Before I create a column or table in a SQL Server database I want to check if the required table and/or columns exist.
I have searched around and found 2 ways so far.
- Stored procedures, which I don't want to use
- By using the
SqlCommand.ExecuteScalar()method and catching an exception to determine if the table/column exists, which for me is a work around but not a perfect solution.
Is there another way to check if table/column exists in SQL Server?
IF EXISTSstatement for that table or column. The real question is, is your database that far out of sync with your application code that the database schema may change between deployments? If that's the case, you have bigger issues.