第十七天 约束条件 序列 视图

约束类型:

1.not null 非空约束

name varchar2(20) constraint student_name_nn not null

2.primary key 主键约束

例:sid int constraint student_sid_pk primary key

3.unique 唯一约束,值不能重复(空值除外)

email varchar2(50) constraint emp_email_uq unique

4.check 条件约束,插入的数据必须满足某些条件

sex char(5) constraint student_sex_ck check(sex in ('man','woman')),
age int constraint student_age_ck check(age between 16 and 20),

5.foreign key 外键

sid int constraint grade_sid_fk references student(sid), 

序列:

序列:

SQL> create sequence test_seq increment by 1 start with 1 maxvalue 1000 nocycle cache 20;

SQL> create table t1(x int primary key, y int);

SQL> insert into t1 values (test_seq.nextval, 11); 反复执行

SQL> select * from t1;

序列是不会回滚的。

视图:

create view student_message as

select s.sid,s.name,g.gid,c.subject,g.score
from student s,grade g,course c;

创建视图就相当于创建了一张虚拟的表。 可以查询。

原文地址:https://www.cnblogs.com/zxk666/p/7281712.html