I need to check if a table in SQL exist or not.
If not it must create one automatically.
Now I researched and found this code:
IF NOT EXISTS (SE
OBJECT_ID()
is a function which returns the Object ID. See the documentation:
Returns the database object identification number of a schema-scoped object.
http://msdn.microsoft.com/en-us/library/ms190328.aspx
By passing it certain parameters (ie. your table details), it will return an ID. You can then compare this with the IDs in the sys.objects
table to check whether it currently exists.