rspec/rules/S2987/rule.adoc

33 lines
735 B
Plaintext

== Why is this an issue?
Executing a ``++DELETE++`` statement without a ``++WHERE++`` clause will delete all rows in a table.
If that is truly what is intended, the ``++TRUNCATE++`` statement should be used because it is faster and uses fewer system and transaction log resources. Moreover when using the ``++TRUNCATE++`` statement, there is no ambiguity about the purpose of the SQL statement.
If removing all content from the table is not what is intended, a ``++WHERE++`` clause should be added.
=== Noncompliant code example
[source,text]
----
DELETE FROM COUNTRIES
----
=== Compliant solution
[source,text]
----
TRUNCATE TABLE COUNTRIES
----
or
[source,text]
----
DELETE FROM COUNTRIES WHERE CODE = country_code
----