📅  最后修改于: 2020-11-16 01:17:23             🧑  作者: Mango
在Oracle中,主键是具有唯一值的列,并且不能为null。在一个表中,只能有一个主键。
CREATE TABLE table_name
(
column1 datatype null/not null,
column2 datatype null/not null,
...
CONSTRAINT constraint_name PRIMARY KEY (column1, column2, ... column_n)
);
CREATE TABLE Test2(ID Number, NAME Varchar2 CONSTRAINT test2_pk PRIMARY KEY (ID));
ALTER TABLE table_name
ADD CONSTRAINT constraint_name PRIMARY KEY (column1, column2, ... column_n);
ALTER TABLE student ADD CONSTRAINT student_pk PRIMARY KEY(id);
ALTER TABLE table_name
DROP CONSTRAINT constraint_name;
ALTER TABLE student DROP CONSTRAINT student_pk ;
ALTER TABLE table_name
DISABLE CONSTRAINT constraint_name;
ALTER TABLE student DISABLE CONSTRAINT student_pk ;
ALTER TABLE table_name
ENABLE CONSTRAINT constraint_name;
ALTER TABLE student ENABLE CONSTRAINT student_pk ;