SQLite DELETE Query

In SQLite, DELETE query is used to delete the existing records from a table. You can use it with WHERE clause or without WHERE clause. WHERE clause is used to delete the specific records (selected rows), otherwise all the records would be deleted.

Syntax:

snippet
DELETE FROM table_name
WHERE [conditions....................];;
Note
Note: We can use N number of "AND" or "OR" operators with "WHERE" clause.

Example:

We have an existing table named "STUDENT", having the following data:

Sqlite Delete query 1

Example1:

Delete the records of a student from "STUDENT" table where ID is 4.

snippet
DELETE FROM STUDENT WHERE ID = 4;
Sqlite Delete query 2

The student's record of id 4 is deleted; you can check it by using SELECT statement:

snippet
SELECT * FROM STUDENT;

Output:

Sqlite Delete query 3

Example2:

If you want to delete all records from the table, don't use WHERE clause.

snippet
DELETE FROM STUDENT;
Sqlite Delete query 4

You can see that there is no data in the table "STUDENT".

Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +