CodesJava

Easy learning with example program codes

DELETE Query in MariaDB

MariaDB DELETE
To remove or delete a single record or multiple records from a table, MariaDB DELETE statement is used.

Syntax: To delete all rows from a table.

DELETE FROM table_name  

Syntax: To delete specific rows from a table.

DELETE FROM table_name  
WHERE conditions;   

Parameters:
table_name: It is used to specify the name of the table to be deleted.
conditions: It is used to specify the conditions to be strictly fulfilled for the deletion process to take place.

Example 1: Deleting one row from a table using multiple conditions.
Students table before removal:

STUDENT_ID	STUDENT_NAME	STUDENT_AGE
1	        Joy	        5
2	        Smiley	        13
3	        Happy	        11
4	        Tom	        10
5	        Jerry	        9
DELETE FROM students
WHERE
    student_age > 10
    AND student_id = 4;

Explanation:
The ‘students’ is an already existing table. The student_age and the student_id are the two columns of the ‘students’ table. Here, we are deleting a row whose student_age is greater than 10 and student_id is 4. To check the output, execute the below query.
SELECT * FROM students;

Students table after removal:

STUDENT_ID	STUDENT_NAME	STUDENT_AGE
1	        Joy	        5
2	        Smiley	        13
3	        Happy	        11
5	        Jerry	        9

Example 2: Deleting multiple rows from a table, using single condition.
Students table before removal:

STUDENT_ID	STUDENT_NAME	STUDENT_AGE
1	        Joy	        5
2	        Smiley	        13
3	        Happy	        11
4	        Tom	        10
5	        Jerry	        9
DELETE FROM students
WHERE
    student_age > 10

Explanation:
The ‘students’ is an already existing table. The student_age is a column of the ‘students’ table. Here, we are deleting all rows whose student_age is 10. To check the output, execute the below query.
SELECT * FROM students;
Students table after removal:
STUDENT_ID STUDENT_NAME STUDENT_AGE
1 Joy 5
5 Jerry 9

Example 3: Deleting all rows from a table.

DELETE FROM students;

Explanation:
The ‘students’ is an already existing table. Here, we are deleting all the rows of the students table, but the table is still there. To check the output, execute the below query.
SELECT * FROM students;

Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status