Artikel ini mencantumkan SQL DELETE
sintaks, seperti yang diterapkan oleh berbagai sistem manajemen basis data (DBMS). Sintaksnya terdaftar persis seperti yang telah dicantumkan oleh setiap vendor di situs web mereka. Klik tautan yang berlaku untuk melihat detail selengkapnya tentang sintaks untuk vendor tertentu.
DBMS yang tercakup adalah MySQL, SQL Server, PostgreSQL, dan Oracle Database.
MySQL
Dari Manual Referensi MySQL 5.7.
Sintaks tabel tunggal:
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROMtbl_name
[PARTITION (partition_name
,...)] [WHEREwhere_condition
] [ORDER BY ...] [LIMITrow_count
]
Sintaks beberapa tabel:
DELETE [LOW_PRIORITY] [QUICK] [IGNORE]tbl_name
[.*] [,tbl_name
[.*]] ... FROMtable_references
[WHEREwhere_condition
]
Atau:
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROMtbl_name
[.*] [,tbl_name
[.*]] ... USINGtable_references
[WHEREwhere_condition
]
SQL Server
Dari Referensi Transact-SQL:
[ WITH <common_table_expression> [ ,...n ] ] DELETE [ TOP ( expression ) [ PERCENT ] ] [ FROM ] { { table_alias | <object> | rowset_function_limited [ WITH ( table_hint_limited [ ...n ] ) ] } | @table_variable } [ <OUTPUT Clause> ] [ FROM table_source [ ,...n ] ] [ WHERE { <search_condition> | { [ CURRENT OF { { [ GLOBAL ] cursor_name } | cursor_variable_name } ] } } ] [ OPTION ( <Query Hint> [ ,...n ] ) ] [; ] <object> ::= { [ server_name.database_name.schema_name. | database_name. [ schema_name ] . | schema_name. ] table_or_view_name }
PostgreSQL
Dari Manual PostgreSQL 9.5:
[ WITH [ RECURSIVE ] with_query [, ...] ] DELETE FROM [ ONLY ] table_name [ * ] [ [ AS ] alias ] [ USING using_list ] [ WHERE condition | WHERE CURRENT OF cursor_name ] [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]
Database Oracle
Dari Dokumentasi Online Database Oracle 12c Rilis 1 (12.1):
DELETE [ hint ] [ FROM ] { dml_table_expression_clause | ONLY (dml_table_expression_clause) } [ t_alias ] [ where_clause ] [ returning_clause ] [error_logging_clause];
DML_table_expression_clause::=
{ [ schema. ] { table [ partition_extension_clause | @ dblink ] | { view | materialized view } [ @ dblink ] } | ( subquery [ subquery_restriction_clause ] ) | table_collection_expression }
partition_extension_clause::=
{ PARTITION (partition) | PARTITION FOR (partition_key_value [, partition_key_value]...) | SUBPARTITION (subpartition) | SUBPARTITION FOR (subpartition_key_value [, subpartition_key_value]...) }
subquery_restriction_clause::=
WITH { READ ONLY | CHECK OPTION } [ CONSTRAINT constraint ]
table_collection_expression::=
TABLE (collection_expression) [ (+) ]
where_clause::=
WHERE condition
returning_clause ::=
{ RETURN | RETURNING } expr [, expr ]... INTO data_item [, data_item ]...
error_logging_clause ::=
LOG ERRORS [ INTO [schema.] table ] [ (simple_expression) ] [ REJECT LIMIT { integer | UNLIMITED } ]
Tentang DELETE
Pernyataan
DELETE
pernyataan adalah bahasa manipulasi data (DML) pernyataan yang menghapus baris tertentu dari tabel.
HAPUS pernyataan menghapus baris yang memenuhi WHERE klausa dari tabel yang ditentukan. Jika WHERE klausa tidak ada, semua baris dalam tabel akan dihapus, sehingga tabel tetap kosong.
Kiat
TRUNCATE
pernyataan (atau dalam kasus SQL Server, TRUNCATE TABLE
pernyataan ) mirip dengan DELETE
pernyataan tanpa WHERE
ayat; namun, TRUNCATE
lebih cepat dan menggunakan lebih sedikit sumber daya sistem dan log transaksi.