Tutorials

SQL Table


SQL Delete table


The data from the table can be deleted if required.

 

DELETE statement is used to delete data (rows) from the table. You can delete specific rows based on the condition defined in WHERE clause.

Syntax to delete all rows

DELETE FROM table_name;

Example

In last chapter we created a table named 'tih_Courses'.

tih_Courses
Course_ID Course_Name Professor Mode_of_Training
001 .Net Mukesh Tiwari Online and Offline
002 Java Rajneesh Shukla Online and Offline
003 ANSI SQL Rajneesh Shukla Online
004 Basics of Computer Shweta  Online

 

Suppose you want to delete all the rows from this table so you need to write the below query:

DELETE FROM tih_Courses;

After the above query is executed, we will be left with empty table as shown below:

Course_ID Course_Name Professor Mode_of_Training
       

 

Syntax to delete particular rows(s)

DELETE FROM table_name WHERE condition;

Example

DELETE FROM tih_Courses WHERE Course_ID = 001;

After the above query is executed, we will be left with the below:

tih_Courses
Course_ID Course_Name Professor Mode_of_Training
002 Java Rajneesh Shukla Online and Offline
003 ANSI SQL Rajneesh Shukla Online
004 Basics of Computer Shweta  Online
 

You can see the row with Course_ID = 001 is deleted from the table.

 

Important Points on Delete statement

  • We can delete a row based on various conditions applied on a single coloumn or on coloumns combined together. We will read in detail about applying condition in WHERE clause tutorial.
  • We can use wild cards as well.
  • Delete is different from drop and truncate.


Please Share this page
Views : 112
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!