I use this command to drop a table in sql-server 2008
IF EXISTS(SELECT name FROM [DBName]..sysobjects WHERE name = N'TableName' AND xtype='U')
DROP TABLE [DBName].[SchemaName].[TableName];
But now I have 2 tables with same name in different schema:
[DBName].[Schema1].[Members]
And
[DBName].[Schema2].[Members]
So, what is your suggestion for check if exist this tables? How can I check table names with schema?
UPDATE:
OK, there is 3 different answers and all of them worked, so I don’t know which one is better, does any one know about use object_id or sys.tables?
Update:
object_idinsys.tablesis the same asobject_idinsysobjectsfor the same table. And is completely the same as function OBJECT_ID returns for the same table name. See the following illustrating examples.So, you may simplify the query:
or in this way:
or for sql2000-styled tables: