| Lesson 6 || Approaches to using literal values |
|| Describe approaches using literal values in your UPDATE and DELETE statements. |
Approaches to using Literal Values(UPDATE DELETE statements)
DELETE statements, you will want to use varying degrees of caution, depending on each individual circumstance.
A cautious approach
If you are not sure how many rows your
DELETE statement will impact, you can issue a
SELECT statement first, using the same criteria.
This will show you how many rows will be affected when you run your query. Your select statement would look like this:
WHERE EmployeeID = 101
An aggressive approach
A more aggressive approach would be to first issue the
statement, then check the value of the SQL Server global variable,
This is aggressive because the rows will already have been updated by the time the
variable is updated.
If more records were impacted than you expected, you have to figure out how to revise them back to their original values.
A medium approach
An approach between these two would be to wrap your statement within a transaction and roll it back if
@@ROWCOUNT is something other than what you expect.
In the next lesson, you will learn about using punctuation with your statements.