Since databases don’t offer "Are you sure?" dialogs, it’s best to be very certain of what you’re changing before you do it.
DELETE statements that don’t precisely limit their effects to single rows risk changing more than was intended. That’s why they should be
This rule raises an issue when an
WHERE clause does not use precisely either a
unique index or all parts of the table’s primary key. That includes both cases where they are omitted in whole or in part, and when they are used but
could still describe multiple rows. E.G.
WHERE AGE = 34, and
WHERE TABLE_ID > 0 AND TABLE_ID < 40.
Note That this rule raises issues only when a database catalog is provided during the SonarQube analysis.
Noncompliant Code Example
CREATE table my_table (
compound_a integer not null,
compound_b integer not null,
primary key (compound_a, compound_b)
DELETE FROM my_table
WHERE compound_b=4; -- Noncompliant
Statements using a cursor and
WHERE CURRENT OF are ignored.