Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • SQL - Getting Started
  • What is SQL
  • Create Table
  • ALTER TABLE Statements
  • Rename Columns
  • Modify Column Type
  • Drop Columns
  • Rename Tables
  • Drop Tables
  • Insert Statement
  • Update Statement
  • Delete Statement
  • Truncate Statement
  • Merge Statement
  • Null Value
  • Select Query
  • WHERE Clause
  • GROUP BY Clause
  • HAVING Clause
  • ORDER BY Clause
  • SQL - Inner Join
  • SQL - Left Join
  • SQL - Right Join
  • SQL - Full Join
  • SQL - BETWEEN
  • SQL - IN
  • SQL - LIKE
  • SQL - INTERSECT
  • SQL - MINUS
  • SQL - UNION
  • SQL - UNION ALL
  • SQL - DISTINCT
  • SQL - ANY, SOME
  • SQL - ALL
  • SQL - AVG()
  • SQL - COUNT()
  • SQL - MAX()
  • SQL - MIN()
  • SQL - SUM()
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

SQL - DELETE Statement

Use the DELETE statement to delete records from the existing table in the current schema or tables of the schema on which you have the DELETE privilege.

Syntax:

DELETE FROM table_name [WHERE Condition];

This DELETE syntax is valid in all the databases such as SQL Server, Oracle, MySQL, PostgreSQL, SQLite, etc. The WHERE clause is optional.

For the demo purpose, the following Employee table in all the examples here.

EmpIdFirstNameLastNameEmailPhoneNoSalary
1'John''King''[email protected]''650.127.1834'33000
2'James''Bond'
3'Neena''Kochhar''[email protected]''123.456.4568'17000
4'Lex''De Haan''[email protected]''123.456.4569'15000

You can delete the specific record(s) from the table using the WHERE clause. The following will delete a record from the Employee table where the value of EmpId is 4.

SQL Script: Delete Records
DELETE FROM Employee WHERE EmpId = 4;

Now, the Select * from Employee query will display the following rows.

EmpIdFirstNameLastNameEmailPhoneNoSalary
1'John''King''[email protected]''650.127.1834'33000
2'James''Bond'
3'Neena''Kochhar''[email protected]''123.456.4568'17000

In the same way, the following will delete all employees from the Employee table whose Salary is more than 20000.

SQL Script: Delete Records
DELETE FROM Employee WHERE Salary > 20000;

Now, the Select * from Employee query will display the following rows.

EmpIdFirstNameLastNameEmailPhoneNoSalary
2'James''Bond'
3'Neena''Kochhar''[email protected]''123.456.4568'17000

The following DELETE statement will delete all the records from the Employee table.

SQL Script: Delete All Rows
DELETE FROM Employee;

Now, the Select * from Employee query will display the empty table.

EmpIdFirstNameLastNameEmailPhoneNoSalary
      

You cannot delete the value of a single column using the DELETE statement. Use the UPDATE statement to set it NULL.

TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.