關於外來鍵約束
CREATE TABLE dept_20 (employee_id NUMBER(4), last_name VARCHAR2(10), job_id VARCHAR2(9), manager_id NUMBER(4), hire_date DATE, salary NUMBER(7,2), commission_pct NUMBER(7,2), department_id, CONSTRAINT fk_deptno FOREIGN KEY (department_id) REFERENCES departments(department_id) );
The foreign key definitions in both variations of this statement omit the ON DELETE clause, causing Oracle to prevent the deletion of a department if any employee works in that department.
CREATE TABLE dept_20 (employee_id NUMBER(4) PRIMARY KEY, last_name VARCHAR2(10), job_id VARCHAR2(9), manager_id NUMBER(4) CONSTRAINT fk_mgr REFERENCES employees ON DELETE SET NULL, hire_date DATE, salary NUMBER(7,2), commission_pct NUMBER(7,2), department_id NUMBER(2) CONSTRAINT fk_deptno REFERENCES departments(department_id) ON DELETE CASCADE );
Because of the first ON DELETE clause, if manager number 2332 is deleted from the employees table, then Oracle sets to null the value of manager_id for all employees in the dept_20 table who previously had manager 2332.
Because of the second ON DELETE clause, Oracle cascades any deletion of a department_id value in the departments table to the department_id values of its dependent rows of the dept_20 table. For example, if Department 20 is deleted from the departments table, then Oracle deletes all of the employees in Department 20 from the dept_20 table
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26870952/viewspace-2151708/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 外來鍵約束
- Javaweb-約束-外來鍵約束JavaWeb
- 約束外來鍵筆記筆記
- 教你mysql如何增加外來鍵約束MySql
- AppBoxFuture(七): 分散式外來鍵約束APP分散式
- oracle外來鍵約束的總結Oracle
- [20180423]關於閃回表與主外來鍵約束.txt
- mysql不能新增外來鍵約束怎麼辦MySql
- SQL外來鍵約束的含義及建立SQL
- Mysql關於資料庫是否應該使用外來鍵約束詳解說明創磅MySql資料庫
- mysql~資料完整性考慮~外來鍵約束MySql
- Mysql-基本練習(06-唯一約束、外來鍵約束、新增、刪除單列)MySql
- 生成指令碼,得到所有表的外來鍵約束,然後刪除並重建這些約束指令碼
- 聊聊Oracle外來鍵約束(Foreign Key)的幾個操作選項Oracle
- 批量刪除MSSQL 中主外來鍵約束SQL
- 資料遷移無法新增外來鍵約束,錯誤程式碼 1215
- MariaDB資料庫的外來鍵約束例項程式碼介紹詳解資料庫
- 主鍵約束、唯一約束和唯一索引索引
- 【MySQL】MySQL進階(外來鍵約束、多表查詢、檢視、備份與恢復)MySql
- [資料庫]資料庫中為什麼不推薦使用外來鍵約束資料庫
- 《資料庫系統概論》5.0——常見約束 大學生學習筆記(主鍵 外來鍵)資料庫筆記
- 【SQL】15 SQL 約束(Constraints)、NOT NULL 約束、UNIQUE 約束、PRIMARY KEY 約束、FOREIGN KEY 約束、CHECK 約束、DEFAULT約束SQLAINull
- 實現 MongoDB 外來鍵關聯MongoDB
- Laravel 學習總結二:get () 和 first () 的區別、@each () 的用法和新增外來鍵約束Laravel
- Django(15)外來鍵和表關係Django
- js關於正則的前後關聯約束(前後預查)JS
- sql運算元據庫(3)-->外來鍵約束、資料庫表之間的關係、三大正規化、多表查詢、事務SQL資料庫
- 主鍵和外來鍵
- sqlserver外來鍵SQLServer
- ORA-02291: 違反完整約束條件 (*) - 未找到父項關鍵字
- 約束
- Mysql truncate table時解決外來鍵關聯MySql
- MySQL 中的約束及相關操作MySql
- indexedDB 內鍵與外來鍵Index
- 10.30 索引,外來鍵索引
- MYSQL的外來鍵MySql
- MySQL 約束MySql
- 03約束