MSSQL分頁存儲進程完全示例(支撐多表分頁存儲)。本站提示廣大學習愛好者:(MSSQL分頁存儲進程完全示例(支撐多表分頁存儲))文章只能為提供參考,不一定能成為您想要的結果。以下是MSSQL分頁存儲進程完全示例(支撐多表分頁存儲)正文
racle應用外鍵來限制子表中參考的字段值,請求子表中的數據必需在主表中存在。當主表的記載產生變更時招致外鍵參考獨一束縛值產生了變更時,Oracle指定了三種舉措:默許值(相似於restrict)、delete cascade和delete set null。(
1.創立父表並初始化數據
SQL> create table t_parent (parent_id int primary key, name varchar2(10)); Table created. SQL> insert into t_parent values (1,'record1'); 1 row created. SQL> insert into t_parent values (2,'record2'); 1 row created. SQL> insert into t_parent values (3,'record3'); 1 row created. SQL> commit; Commit complete.
2.創立三品種型的子表t_child1、t_child2和t_child3
(1)no action種別
SQL> create table t_child1 (child1_id int primary key, parent_id int); Table created. SQL> alter table t_child1 add constraint FK_t_child1 foreign key (parent_id) references t_parent (parent_id); Table altered. SQL> insert into t_child1 values (1,1); 1 row created. SQL> commit; Commit complete.
(2)cascade類型
SQL> create table t_child2 (child2_id int primary key, parent_id int); Table created. SQL> alter table t_child2 add constraint FK_t_child2 foreign key (parent_id) references t_parent (parent_id) on delete cascade; Table altered. SQL> insert into t_child2 values (2,2); 1 row created. SQL> commit; Commit complete.
(3)SET NULL類型
SQL> create table t_child3 (child2_id int primary key, parent_id int); Table created. SQL> alter table t_child3 add constraint FK_t_child3 foreign key (parent_id) references t_parent (parent_id) on delete set null; Table altered. SQL> insert into t_child3 values (3,3); 1 row created. SQL> commit; Commit complete.
3.確認主表和子表中的數據
SQL> select * from T_PARENT; PARENT_ID NAME ---------- ---------- 1 record1 2 record2 3 record3 SQL> select * from T_CHILD1; CHILD1_ID PARENT_ID ---------- ---------- 1 1 SQL> select * from T_CHILD2; CHILD2_ID PARENT_ID ---------- ---------- 2 2 SQL> select * from T_CHILD3; CHILD2_ID PARENT_ID ---------- ---------- 3 3
4.測驗考試對具有默許類型外鍵參照的主表記載停止刪除
SQL> delete from T_PARENT where parent_id = 1; delete from T_PARENT where parent_id = 1 * ERROR at line 1: ORA-02292: integrity constraint (HBHE.FK_T_CHILD1) violated - child record found SQL> select * from T_CHILD1; CHILD1_ID PARENT_ID ---------- ---------- 1 1
在此類型下,不許可刪除操作
5.測驗考試對具有delete cascade類型外鍵參照的主表記載停止刪除
SQL> delete from T_PARENT where parent_id = 2; 1 row deleted. SQL> select * from T_CHILD2; no rows selected
級聯刪除勝利
6.測驗考試對具有delete set null類型外鍵參照的主表記載停止刪除
SQL> delete from T_PARENT where parent_id = 3; 1 row deleted. SQL> select * from T_CHILD3; CHILD2_ID PARENT_ID ---------- ---------- 3
主表記載可以完成刪除,子表中對應的內容被設置為NULL。