Creating Procedures to Delete Data

As with procedures that update data, you should check to see whether there are relationships that need to be checked and maintained in the database. There are two ways to do this:

  • Use triggers that are fired when a delete statement is run against the table. These triggers can then perform the required deletions in other tables. There can be issues with this approach, especially when the delete statement recursively fires many other triggers. For more information on this, see Chapter 15, "Writing Triggers."

  • Use stored procedures to perform this functionality. This way, you can delete any other rows from other tables referenced by the table from which you are deleting. Listing 8.2 shows the code for this type of ...

Get Writing Stored Procedures for Microsoft SQL Server now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.