SQL Tutorial
SQL Database
SQL Table
SQL Select
SQL Order By
SQL Insert
SQL Update
SQL Delete
Difference
SQL Injection
SQL String Functions
Miscl
- SQL Formatter
- SQL group by
- SQL add/drop/update column operation
- SQL CAST Function
- SQL Comments
- SQL CONCAT Function
- CTE (Common Table Expression)SQL
- How to use distinct in SQL?
- Joining Three or More Tables in SQL
- What is Web SQL?
- How to create functions in SQL?
- How to run SQL Script?
- How to Delete Duplicate Rows in SQL?
- Nth Highest salary
- 12 Codd's Rules
- SQL EXCEPT
- Types of SQL JOIN
- Change datatype of column in SQL
- SQL Auto Increment
- SQL Like
- Commit and Rollback in SQL
- SQL Concatenate
- SQL get month from the date
- Savepoint in SQL
- SQL ORDER BY DATE
- TIME Datatype in SQL
- SQL BETWEEN
- CRUD Operations in SQL
- SQL INDEX
- Scalar Functions in SQL
- SET Operators in SQL
- Types of SQL Commands
- TCL Commands in SQL
- SQL Subquery
- SQL View
- Constraints in SQL
- Pattern Matching in SQL
- SQL Date Functions
- DDL Commands in SQL
- DML Commands in SQL
- SQL CASE
- SQL Inner Join
- SQL IN Operator
- Check Constraint in SQL
- SQL CLAUSES
- SQL LOGICAL OPERATORS
- Delete Column from Table
- Add Column in the Table
- Delete one row in SQL
- Change the Column Value
- How to Add Foreign Key in SQL
- Add a Primary Key
- Insert One or More rows
- How to Use LIKE in SQL
- Cursor in SQL
- Difference Between DROP and Truncate
- SQL Comparison Operators
- SQL COUNT WHERE
- SQL SELECT MIN
- SQL Stored Procedure
- SQL SELECT AVG
- SQL SELECT MAX
- SQL ADD COLUMN
- How to use Auto-Increment in SQL
- SQL Languages
- SQL Arithmetic Operators
- How to Use GROUP BY in SQL
- How to Use ORDER BY in SQL
- Trigger in SQL
- What is Race Condition
- SQL COUNT DISTINCT
PL/SQL Tutorial
Sql Interview Question
SQl Quiz
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:
- Create a Database.
- Create a Table and Insert the data into the table.
- Show the table before deletion.
- Delete one record from the table.
- 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:
(
column_Name_1 data type (size of the column_1),
column_Name_2 data type (size of the column_2),
column_Name_3 data type (size of the column_3),
...
column_Name_N data type (size of the column_N)
);
Suppose you want to create the Student table with five columns in the College database. For this, you have to write the following query:
(
Roll_No Int,
First_Name Varchar (20),
City Varchar (20),
Age Int,
Marks Int,
) ;
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:
(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 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.