Our company is migrating one of its products from SQL Server 2005 to 2008, and in the logs I've noticed excess of errors about deleting tables if it does not exist. In SQL Server 2005 we had this to delete tables
IF OBJECT_ID('dbo.Units', 'U') IS NOT NULL
DROP TABLE dbo.Units
which doesn't seem to work anymore.
What would be the proper way of deleting a table only if it exists in SQL Server 2008?
This should do it!
IF EXISTS
(SELECT
TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'TableToDrop')
DROP TABLE TableToDrop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With