Oracle中給表新增主鍵 外來鍵

2021-08-25 17:52:57 字數 656 閱讀 3497

1、建立表的同時建立主鍵約束

(1)無命名 create table student ( studentid int primary key not null, studentname varchar(8), age int);

(2)有命名 create table students ( studentid int , studentname varchar(8), age int, constraint yy primary key(studentid));

2、刪除表中已有的主鍵約束

(1)無命名可用 select * from user_cons_columns; 查詢表中主鍵名稱得student表中的主鍵名為sys_c002715 alter table student drop constraint sys_c002715;

(2)有命名 alter table students drop constraint yy;

3、向表中新增主鍵約束 alter table student add constraint pk_student primary key(studentid);

4、向表中新增外來鍵約束 alter tabletable_aadd constraint fk_name foreign key(id) references table_b(id);

Oracle中給表新增主鍵 外來鍵

一 建立表的同時建立主鍵約束 1 無命名 create table student studentid int primary key not null,studentname varchar 8 age int 2 有命名 create table students studentid int s...

Oracle中給表主鍵 外來鍵收集

1 建立表的同時建立主鍵約束 1 無命名 create table student studentid int primary key not null,studentname varchar 8 age int 2 有命名 create table students studentid int s...

Oracle表中新增外來鍵約束

新增主鍵約束 alter table ga airline add constraint pk airline id primary key airline id 有三種形式的外來鍵約束 1 普通外來鍵約束 如果存在子表引用父表主鍵,則無法刪除父表記錄 2 級聯外來鍵約束 可刪除存在引用的父表記錄,...