alter table – sql 命令示例

示例 1 往表 customer 中添加字段 fax, 并且允许字段有空值。
示例 2 使 cust_id 字段为 customer 表的主关键字。
示例 3 给 orders 表中的 quantity 字段添加有效性规则,使字段 quantity 的值非负。
示例 4 基于表 customer 的关键字 cust_id和表 orders 中的候选关键字 cust_id,建立 customer 和 orders 间的一对多永久关系。
示例 5 删除表 orders 的 quantity 字段的有效性规则。
示例 6 删除表 customer 和表 orders 间的永久关系,但保持 orders 表中的 cust_id 索引标识。

*示例 1
set path to (home( ) + 'samples\data\') 
&& 为表设置路径
alter table customer add column fax c(20) null

*示例 2
alter table customer add primary key cust_id tag cust_id

alter table customer alter column cust_id c(5) primary key

*示例 3
alter table orders;
alter column quantity set check quantity >= 0;
error "quantities must be non-negative"

*示例 4
alter table orders;
add foreign key cust_id tag cust_id references customer

*示例 5
alter table orders alter column quantity drop check

*示例 6
alter table orders drop foreign key tag cust_id save