在Oracle 10g中创建表时,如何指定候选键和外键?
答案 0 :(得分:1)
关于rics:
CREATE TABLE supplier
( supplier_id numeric(10) not null,
supplier_name varchar2(50) not null,
CONSTRAINT supplier_pk PRIMARY KEY (supplier_id),
CONSTRAINT supplier_unique_name UNIQUE (supplier_name)
);
CREATE TABLE supplier_parts
( supplier_id numeric(10) not null,
part_name varchar2(50) not null,
CONSTRAINT supplier_id_fk FOREIGN KEY (supplier_id)
REFERENCES supplier (supplier_id)
);
CREATE TABLE silly
( supplier_name varchar2(50),
CONSTRAINT supplier_name_fk FOREIGN KEY (supplier_name)
REFERENCES supplier (supplier_name)
);
在上面的示例中,supplier_pk
是主键。 supplier_pk
和supplier_unique_name
是候选键。 supplier_id_fk
和supplier_name_fk
是参照完整性约束(或外键)。
答案 1 :(得分:0)
候选键是唯一标识表中行的键。它可以用作表的主键。例如:
CREATE TABLE supplier
( supplier_id numeric(10) not null,
supplier_name varchar2(50) not null,
contact_name varchar2(50),
CONSTRAINT supplier_pk PRIMARY KEY (supplier_id)
);