If you need to check if an object exists in the database, rather than querying an obscure system table, you can use the OBJECT_ID function. If you want to verify that the table FooBar exists in the YadiYada database, simply write the following IF statement: IF OBJECT_ID('YadiYada..FooBar') IS NOT NULL
BEGIN
--FooBar exists so you can use it here
--...
END
posted by Oskar Austegard at 8:31 PM on Jul 11, 2007
"SQL: Does the object exist?"
No comments yet. -