oracle创建外键约束的两种方式
生活随笔
收集整理的這篇文章主要介紹了
oracle创建外键约束的两种方式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、創(chuàng)建表時直接創(chuàng)建外鍵約束
create table books(bookid number(10) not null primary key,bookName varchar2(20) not null,price number(10,2),categoryId number(10) not null references Category(id) --外鍵約束 );備注:必須先創(chuàng)建參照表,才能在創(chuàng)建外鍵約束,即必須現有表Category,再有book
2、先創(chuàng)建表,表創(chuàng)建成功后,單獨添加外鍵約束
create table books(bookid number(10) not null primary key,bookName varchar2(20) not null,price number(10,2),categoryId number(10) not null );ALTER TABLE books ADD CONSTRAINT FK_Book_categoryid FOREIGN KEY(categoryId ) REFERENCES Category(id);總結
以上是生活随笔為你收集整理的oracle创建外键约束的两种方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle中用一个序列给两个表创建主键
- 下一篇: Oracle包和包体以及与非包体定义函数