Does Table Exist
-
Environemnt: VC++6,Access DB via ODBC. How would one determine if a table exists in the database. I have tried "SELECT * FROM TABLE_NAME" where TABLE_NAME is the table I want to check for existence. Thinking I would get an error or invalid return, Yet the the error gets trap and an caught before I can get to it or test for a return condition? There has to be an easy way to check for table existance. RIGHT? Thanks for any help --Errol
-
Environemnt: VC++6,Access DB via ODBC. How would one determine if a table exists in the database. I have tried "SELECT * FROM TABLE_NAME" where TABLE_NAME is the table I want to check for existence. Thinking I would get an error or invalid return, Yet the the error gets trap and an caught before I can get to it or test for a return condition? There has to be an easy way to check for table existance. RIGHT? Thanks for any help --Errol
Try this:
IF EXISTS (SELECT name FROM sysobjecs WHERE id = object_id(N'tablename')
AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
SELECT * FROM tablenameOr to get a list of tables (using this query in the EXISTS clause above also works), this is even easier:
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
"Well, I wouldn't say I've been missing it, Bob." - Peter Gibbons