Versions available for this page: CUBRID 8.2.1 | CUBRID 8.3.0 | CUBRID 8.3.1 | CUBRID 8.4.0 | CUBRID 8.4.1 | CUBRID 8.4.3 | CUBRID 9.0.0 |
You can delete records in the table by using the DELETE statement. You can specify delete conditions by combining the statement with the WHERE Clause. You can delete multiple tables. You can delete one or more tables with one DELETE statement.
If you want to delete one table, the LIMIT Clause can be specified. You can limit the number of records by specifying the LIMIT Clause. If the number of records satisfying the WHERE Clause exceeds row_count, only the number of records specified in row_count will be deleted.
<DELETE single table>
DELETE [FROM] table_name [ WHERE <search_condition> ] [LIMIT row_count]
<DELETE multiple tables FROM ...>
DELETE table_name[, table_name] ... FROM <table_specifications> [ WHERE <search_condition> ]
<DELETE FROM multiple tables USING ...>
DELETE FROM table_name[, table_name] ... USING <table_specifications> [ WHERE <search_condition> ]
CREATE TABLE a_tbl(
id INT NOT NULL,
phone VARCHAR(10));
INSERT INTO a_tbl VALUES(1,'111-1111'), (2,'222-2222'), (3, '333-3333'), (4, NULL), (5, NULL);
DELETE FROM a_tbl WHERE phone IS NULL LIMIT 1;
--delete one record only from a_tbl
SELECT * FROM a_tbl;
id phone
===================================
1 '111-1111'
2 '222-2222'
3 '333-3333'
5 NULL
--delete all records from a_tbl
DELETE FROM a_tbl;
CREATE TABLE a_tbl(
id INT NOT NULL,
phone VARCHAR(10));
CREATE TABLE b_tbl(
id INT NOT NULL,
phone VARCHAR(10));
CREATE TABLE c_tbl(
id INT NOT NULL,
phone VARCHAR(10));
INSERT INTO a_tbl VALUES(1,'111-1111'), (2,'222-2222'), (3, '333-3333'), (4, NULL), (5, NULL);
INSERT INTO b_tbl VALUES(1,'111-1111'), (2,'222-2222'), (3, '333-3333'), (4, NULL);
INSERT INTO c_tbl VALUES(1,'111-1111'), (2,'222-2222'), (10, '333-3333'), (11, NULL), (12, NULL);
-- Below four queries show the same result.
-- <DELETE multiple tables FROM ...>
DELETE a, b FROM a_tbl a, b_tbl b
WHERE a.id=b.id;
DELETE a, b FROM a_tbl a INNER JOIN b_tbl b ON a.id=b.id
INNER JOIN c_tbl c ON b.id=c.id;
-- <DELETE FROM multiple tables USING ...>
DELETE FROM a, b USING a_tbl a, b_tbl b, c_tbl c
WHERE a.id=b.id AND b.id=c.id;
DELETE FROM a, b USING a_tbl a INNER JOIN b_tbl b ON a.id=b.id
INNER JOIN c_tbl c ON b.id=c.id;