Working with Triggers and Transactions

In a relational database, data in a table is related to other tables. Therefore, while manipulating data in one table, you need to verify and validate its effect on data in the related tables. In addition, you might need to manipulate data in a table after inserting or updating data in another table. You also need to ensure that if an error occurs while updating the data in a table, the changes are reverted. | Working with Triggers and Transactions Chapter 8 In a relational database data in a table is related to other tables. Therefore while manipulating data in one table you need to verify and validate its effect on data in the related tables. In addition you might need to manipulate data in a table after inserting or updating data in another table. You also need to ensure that if an error occurs while updating the data in a table the changes are reverted. This helps in maintaining data integrity. The SQL Server allows you to implement triggers and transactions to maintain data integrity. This chapter explains different types of triggers that can be created in SQL Server 2005. Next it discusses how to implement triggers to enforce data integrity. Further it explains how to implement transactions. Objectives In this chapter you will learn to fl Implement triggers fl Implement transactions Implementing Triggers At times while performing data manipulation on a database object you might also need to perform another manipulation on another object. For example in an organization the employees use the Online Leave Approval system to apply for leaves. When an employee applies for a leave the leave details are stored in the LeaveDetails table. In addition a new record is added to the LeavesForApproval table. When the supervisors log on to the system all the leaves pending for their approval are retrieved from the LeavesForApproval table and displayed to them. To perform such operations the SQL Server allows you to implement triggers. A trigger is a block of code that constitutes a set of T-SQL statements activated in response to certain actions such as insert or delete. Triggers are used to ensure data integrity before or after performing data manipulations. Before you implement a trigger it is important to know the different types of triggers that can be created by using SQL Server 2005. Identifying Types of Triggers In the SQL Server various kinds of triggers can be used for .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.