Home:ALL Converter>How do I specify a candidate key and a foreign key when creating a table in Oracle 10g?

How do I specify a candidate key and a foreign key when creating a table in Oracle 10g?

Ask Time:2010-09-20T05:00:55         Author:Rn2dy

Json Formatter

How do I specify a candidate key and a foreign key when creating a table in Oracle 10g?

Author:Rn2dy,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/3747465/how-do-i-specify-a-candidate-key-and-a-foreign-key-when-creating-a-table-in-orac
Jeffrey Kemp :

Following on from rics:\n\nCREATE TABLE supplier\n( supplier_id numeric(10) not null,\n supplier_name varchar2(50) not null,\n CONSTRAINT supplier_pk PRIMARY KEY (supplier_id),\n CONSTRAINT supplier_unique_name UNIQUE (supplier_name)\n);\n\nCREATE TABLE supplier_parts\n( supplier_id numeric(10) not null,\n part_name varchar2(50) not null,\n CONSTRAINT supplier_id_fk FOREIGN KEY (supplier_id)\n REFERENCES supplier (supplier_id) \n);\n\nCREATE TABLE silly\n( supplier_name varchar2(50),\n CONSTRAINT supplier_name_fk FOREIGN KEY (supplier_name)\n REFERENCES supplier (supplier_name) \n);\n\n\nIn the above example, supplier_pk is a Primary key. supplier_pk and supplier_unique_name are candidate keys. supplier_id_fk and supplier_name_fk are Referential Integrity constraints (or Foreign keys).",
2010-09-20T04:49:20
yy