5.5.3. Adding a Constraint

5.5.3. Adding a Constraint
5.5.3.添加约束
To add a constraint, the table constraint syntax is used. For example:
使用表约束语法添加约束。例如:
 
ALTER TABLE products ADD CHECK (name <> '');
ALTER TABLE products ADD CONSTRAINT some_name UNIQUE (product_no);
ALTER TABLE products ADD FOREIGN KEY (product_group_id) REFERENCES product_groups;
 
To add a not-null constraint, which cannot be written as a table constraint, use this syntax:
添加非空约束,不能使用表级约束,语法如下:
 
ALTER TABLE products ALTER COLUMN product_no SET NOT NULL;
 
The constraint will be checked immediately, so the table data must satisfy the constraint before it can  be added.
约束检查会立即执行,所以在添加约束之前必须要确保表中的数据满足该约束要求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值