Issues Involved When Updating the Primary Key of a Parent Row

Issues Involved When Updating the Primary Key of a Parent Row In this section, you'll learn about the issues involved when attempting to update the primary key in a parent DataTable | Issues Involved When Updating the Primary Key of a Parent Row In this section you ll learn about the issues involved when attempting to update the primary key in a parent DataTable and then pushing the update to the underlying database table. The issues occur when the child database table already contains rows that use the primary key you want to change in the parent table. The examples in this section will use the Customers and Orders table which are related through the foreign key on the CustomerlD column of the Orders table to the CustomerlD column of the Customers table. As you ll learn you re much better off not allowing changes to the primary key column of a table. If you allow changes to the primary key column then as you ll see shortly you can run into problems when pushing the change to the database. Instead you should set the ReadOnly property to true for the primary key DataColumn in your parent DataTable and also set ReadOnly to true for the foreign key DataColumn in your child DataTable. That prevents changes to the values in these DataColumn objects. If you really need to change the primary key and foreign key values you should delete and then recreate the rows in the database with the new primary key and foreign key values. You can control how updates and deletes are performed using the properties of the foreign key in the SQL Server database and also the UpdateRule and DeleteRule properties of a ForeignKeyConstraint object. You ll explore both of these items in the following sections. Controlling Updates and Deletes Using SQL Server You can control how updates and deletes are performed using SQL Server by setting the properties of the foreign key. You set these properties using the Relationships tab of a database table s Properties dialog box. You open this dialog box in Enterprise Manager for the Orders table by performing the following steps 1. Right-click the Orders table in the Tables node of Enterprise Manager. 2. Select Design Table from the .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU LIÊN QUAN
5    176    1
5    255    1
5    106    0
5    121    1
6    103    1
6    107    1
6    121    1
6    103    0
6    140    0
6    98    0
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.