分享知識-快樂自己:Oracle基本語法(建立:表空間、使用者、授權、約束等)使用指南
阿新 • • 發佈:2018-12-19
--2.1)建立主鍵約束--
alter table Student add constraint PK_Student_StuId primary key(StuId);
alter table StuClass add constraint PK_StuClass_ClassId primary key(ClassId);
--2.2) 建立檢查約束--
alter table Student add constraint CK_Student_Gender check(gender='男' or gender='女');
alter table Student add constraint CK_Student_Age check(Age >=0 and Age<=100);
--2.3)建立唯一約束--
alter table Student add constraint UQ_Student_StuName unique(StuName);
--2.4)建立預設約束--
--alter table Student add constraint DF_Student_Address default('地址不詳');
alter table Student Modify Address varchar(50) default '地址不詳';
alter table Student Modify JoinDate Date default sysdate;
--2.5)建立外來鍵約束--
alter table Student add constraint FK_Student_StuCLass_ClassId foreign key(ClassId) references StuClass(ClassId);