Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Is the following query the right one?

IF EXISTS(SELECT *
          FROM   dbo.HENRY)
  DROP TABLE dbo.HENRY


F.Y.I - Table name: HENRY

What I have tried:

Please look above query, I tried the above code but don't have a compiler as of now, need to prepare for my theory exam for SQL
Posted
Updated 25-Sep-22 0:26am

Take a look here: https://www.sqlshack.com/overview-of-the-t-sql-if-exists-statement-in-a-sql-server-database/[^]

There you'll find instruction how to determine if an object of database exists:
- IF EXISTS in SQL 2014 or before
- DROP ..IF EXISTS in SQL Server 2016 to SQL Server 2019
 
Share this answer
 
If you are using Sql Server 20016 and up, a better command would be:
SQL
DROP TABLE IF EXISTS dbo.Henry
 
Share this answer
 
Comments
Richard Deeming 22-Sep-22 5:43am    
20016? I've obviously been asleep for longer than I though! 🤣
OriginalGriff 22-Sep-22 6:09am    
Don't tell me you are still running Windows 666? :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900