EN
MS SQL Server - Drop table if exists
0
points
In this article, we would like to show you how to DROP TABLE IF EXISTS
in MS SQL Server.
Quick solution:
DROP TABLE IF EXISTS [table_name];
Practical example
In this example, we will delete the users
table.
Query:
DROP TABLE IF EXISTS [users];
Output:
Database preparation
create_tables.sql
file:
CREATE TABLE [users] (
[id] INT IDENTITY(1,1),
[name] VARCHAR(50) NOT NULL,
[surname] VARCHAR(50) NOT NULL,
[department_id] INT,
[salary] DECIMAL(15,2) NOT NULL,
PRIMARY KEY ([id])
);