Javatpoint Logo
Javatpoint Logo

How to Delete one row in SQL

Here, you will learn how to delete one row or record from a table in Structured Query Language.

We can easily delete one record using the SQL DELETE statement. This statement also removes all the existing rows from the database tables. It also helps in removing the data from the SQL views.

Once a row has been deleted from the table, that row cannot be recovered.

The SQL syntax for deleting a specific row is given below:

In this syntax, the WHERE clause specifies that record which you want to remove from the table. If you run the DELETE command without WHERE clause, the query will remove all the rows from the SQL table.

If you want to remove the records permanently from the table, you have to follow the following steps one by one in the given order:

  1. Create a Database.
  2. Create a Table and Insert the data into the table.
  3. Show the table before deletion.
  4. Delete one record from the table.
  5. Show the table after deletion.

Now, we are going to explain the above steps with an example:

Step 1: Create a Database

In the Structured Query Language, creating a database is the first step for storing the structured tables in the database.

Use the following SQL command to create a database:

Suppose you want to create a College database. For this operation, you have to type the following command in Structured Query Language:

Step 2: Create a Table and Insert the data

After database creation, you can create the table in the database with the help of the following syntax:

Suppose you want to create the Student table with five columns in the College database. For this, you have to write the following query:

Now, you have to insert the data in the table using the following syntax:

You can easily insert the data of college students in the Student table using the following query in SQL:

Step 3: View the Inserted Data

After table creation and data insertion, you can view the inserted data of the Student table by typing the following query in your SQL application:


Roll_No Name City Age Marks
101 Akash Delhi 18 89
102 Bhavesh Kanpur 19 93
103 Yash Delhi 20 89
104 Bhavna Delhi 19 78
105 Yatin Lucknow 20 75
106 Ishika Ghaziabad 19 91
107 Vivek Goa 20 80

Step 4: Delete One Record from the table

The following query deletes the record of the specific student from the above student table:

Step 5: View the Table after Deletion

To check the result of the query executed in the 4th step, you have to use the following SELECT command in SQL:


Roll_No Name City Age Marks
101 Akash Delhi 18 89
103 Yash Delhi 20 89
104 Bhavna Delhi 19 78
105 Yatin Lucknow 20 75
106 Ishika Ghaziabad 19 91
107 Vivek Goa 20 80

As you can see that one row has been successfully deleted from the Student table based on the situation specified in the WHERE clause of the DELETE query.

Delete Multiple Records from the table

If you want to delete the multiple rows from the Students table, you have to write the below query in your SQL application:

To check the result of the above query, you have to write the following SELECT query in SQL:


Roll_No Name City Age Marks
101 Akash Delhi 18 89
103 Yash Delhi 20 89
104 Bhavna Delhi 19 78

As we can see that more than one row has been deleted from the Student table according to the condition specified in the WHERE clause of the DELETE statement.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA