时间:2021-07-01 10:21:17 帮助过:3人阅读
create table student(
sno number(10),
sname varchar2(100),
sage number(3),
ssex char(4),
sbirth date,
sqq varchar2(30),
constraint pk_student_sno primary key(sno) ---添加主键约束
);
create table student( sno number(10), sname varchar2(100), sage number(3), ssex char(4), sbirth date, sqq varchar2(30) );
alter table student add constraint pk_student_sno primary key(sno);
alter table student drop constraint pk_student_sno;
select * from student for update;
drop table student;
非空约束
三种方式
create table student( sno number(10) primary key, sname varchar2(100) not null, sage number(3), ssex char(4), sbirth date, sqq varchar2(30) );
create table student(
sno number(10) primary key,
sname varchar2(100),
sage number(3),
ssex char(4),
sbirth date,
sqq varchar2(30),
constraints ck_student_sname check(sname is not null)
);
create table student( sno number(10) primary key, sname varchar2(100), sage number(3), ssex char(4), sbirth date, sqq varchar2(30) );
alter table student add constraint ch_student_sname check(sname is not null);
alter table student drop constraint ch_student_sname
检查约束
create table student( sno number(10) primary key, sname varchar2(100) not null, sage number(3) check(sage<150 and sage>0), ssex char(4) check(ssex =‘男‘ or ssex = ‘女‘), sbirth date, sqq varchar2(30) );
create table student( sno number(10) primary key, sname varchar2(100) not null, sage number(3), ssex char(4) check(ssex =‘男‘ or ssex = ‘女‘), sbirth date, sqq varchar2(30), constraint ch_student_sage check(sage<150 and sage>0) );
create table student( sno number(10) primary key, sname varchar2(100) not null, sage number(3), ssex char(4) check(ssex =‘男‘ or ssex = ‘女‘), sbirth date, sqq varchar2(30) );
alter table student add constraint ch_student_sage check(sage<150 and sage>0);
alter table student drop constraint ch_student_sage;
oracle--约束(主键、非空、检查)
标签:默认值 traints sel def ble play lte one 关键字