Oracel 修改約束命令

2022-08-02 06:24:06 字數 1049 閱讀 8494

增加修改列的約束:

alter table dep_1

modify

(dep_id number(5) default 8 constraint dep_1_id_nn not  null)

--非空約束                               

修改表的約束

(例如設定主鍵)

alter

table dep_1

add constraint dep_1_id_pkprimary key(dep_id)

alter table dep_1

modify

(constraint dep_1_id_pk primary key(dep_id))

(設定外來鍵)

alter table grade_1

add constraint grade_dep_1_fk foreign key(dep) references dep_1(dep_id)on delete cascade

--當父表記錄刪除,對應子表記錄都刪除

alter table grade_1

add constraint grade_dep_1_fk foreign key(dep) references dep_1(dep_id)on delete set null

--當父表記錄刪除,對應子表記錄外來鍵置null

(自定義約束check)

alter table dep_1

add constraint dep_1_nm_len check(length(dep_name) >= 2)

刪除表的約束

alter table dep_1

drop

constraint dep_1_id_pkcascade

--刪除主鍵,若此主鍵是其他表的外來鍵,要用cascade引數將那張表的外來鍵一齊刪除。

MySQL修改約束

alter table 表名 modify column 欄位名 字段型別 新約束 例如 alter table student modify column age int not null 新增字段唯一 alter table student modify column stu nu varcha...

MySQL修改約束

新增主鍵約束 alter table tbl name add constraint symbol索引名 primary key index type index col name1,index col name2,刪除主鍵約束 alter table tbl name drop primary k...

MySQL 新增約束,修改約束,刪除約束

alter table 新增,修改,刪除表的列,約束等表的定義。檢視列 desc 表名 修改表名 alter table t book rename to bbb 新增列 alter table 表名 add column 列名 varchar 30 刪除列 alter table 表名 drop ...