devxlogo

Using T-SQL to Check Whether a Table Exists

Using T-SQL to Check Whether a Table Exists

Assume that an application creates a new table every month. The table name can be coined using some pattern, like sales0501, sales0502,, etc.

To identify whether a particular table exists in a database, the following query can be used in the application:

"select name from sysobjects where xtype='u' and name = @tblName"

@tblName is the table name to be searched in the database and @tblName is the input parameter for the query.

devx-admin

Share the Post: