SQL-续
not null 与 unique
not null
略
unique
1unique (A_1, A_2, ... , A_n)
后接属性集,可作为候选码。
check
类似where,后面接条件。
12345create table s_table ( ..., ..., check (a_1 in ('ABC', 'WIN', 'DES')) )
外码约束
12foreign key S references table_name
级联
1234567891011121314create table main_table ( A char(5) primary key, other_id varchar(60) references f_table on delete cascade on update cascade, ...);create table other_name ( other_id int(11) primary key, other_other char(1) not null);
check
12check (time_slot_id in (select time_slot_id from time_slot));
作用
当某个属性只是参照完整性约束下的码而不是外码,可以用check clause对这种情况进行描述。
在创建表的时候描述为对某种参照情况的描述。
index
1234567891011create table main_table ( A char(5) primary key, other_id varchar(60) references f_table on delete cascade on update cascade, ...);create index A_index on main_table(A);
作用
可以快速检索,详见11章
create type
12create type Dollars as numeric(12, 2) final;
大数存储
blob 数字型大数clob 字符型大数
授权
Authorization
数据授权
Read: allow reading.Insert: allow insert, not modification.Update: allow modification.Delete: allow deletion.结构授权
Index: allow create and deletion of Indices.Resourse: allow creation of relation.Alteration: allow addition or deletion of attribute in a relation.Drop: allow deletion of relations.
grant
1grant <priviege list> on <relation name or view name> to <user list>;
<priviege list>:
insertupdatedeleteselectall privieges
<user list>:
a user-idpublic, allow all user valid users the priviledge granteda role
revoke
回收权限
1revoke <priviledge list>;
all 代表全体用户。
public 代表非指明的用户。
特殊情况
当某个用户在同一个权限上被授予两次,每次调用revoke会回收其中一条权限。
role
12craete role instructor;grand instructor to Amit;
作用
当某个用户从表中删除,其关联的角色所授予的权限仍然有效。