Languages
[Edit]
EN

MS SQL Server - Drop table if exists

0 points
Created by:
Elleanor-Williamson
260

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:

MS SQL Server - DROP TABLE IF EXISTS result in HeidiSQL (before)
MS SQL Server - DROP TABLE IF EXISTS result in HeidiSQL (before)
MS SQL Server - DROP TABLE IF EXISTS result in HeidiSQL (after)
MS SQL Server - DROP TABLE IF EXISTS result in HeidiSQL (after)

 

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])
);
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

MS SQL Server - problems

MS SQL Server - Drop table if exists
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join