Monday, June 16, 2014

Sql Check if Object Exists


You know those situations where you want to drop and recreate something, or create something if it doesn't exist?  You can use the object_id function to check if an object exists in the database.

PRINT 'Object Does not Exist'
'Object Exists'

Other object_id syntax options:

  • With server and schema: OBJECT_ID('MyServer.MySchema.MyTableName')
  • Just tables: OBJECT_ID('MyServer.MySchema.MyTableName''U')
Thanks to

No comments:

Post a Comment

Please only include comments that add to the substance of the Blog Post:
- Question or request for clarification
- Idea for improvement
- Identifying an issue

Please refrain from promotion.