问题描述
如何在 8n sql (Oracle 11g) 中添加约束,如非空、检查、默认、唯一、主键等 以及如何删除上面写的相同内容。
解决方法
怎么样?通过使用适当的命令 (ALTER TABLE
),遵循每个约束的语法。如需了解详情,请阅读文档。
几个例子:
SQL> create table test (id number);
Table created.
SQL> alter table test add constraint pk_test primary key (id);
Table altered.
SQL> alter table test modify id not null;
Table altered.
SQL> alter table test add constraint ch_test
2 check (id > 20);
Table altered.
SQL>