Foreign Key Oracle | Foreign Key - oracle tutorial - sql tutorial

Learn oracle - oracle tutorial - Oracle foreign key - oracle examples - oracle programs
What is oracle foreign key ?
- A foreign key means that values in one table must also appear in another table.
- The referenced table is called the parent table while the table with the foreign key is called the child table. The foreign key in the child table will generally reference a primary key in the parent table.

oracle tutorial , sql tutorial , sql , pl sql tutorial , oracle , pl sql , plsql
Syntax:
CREATE TABLE table_name
(
column1 datatype null/not null,
column2 datatype null/not null,
...
CONSTRAINT fk_column
FOREIGN KEY (column1, column2, ... column_n)
REFERENCES parent_table (column1, column2, ... column_n));
click below button to copy the code. By - oracle tutorial - team
Example:
CREATE TABLE wikitechy3
(
tech_Id number(1) PRIMARY KEY,
tech_No number(4)
)
CREATE TABLE wikitechy1
(
wiki_Id int NOT NULL,
wiki_No int NOT NULL,
tech_Id int,
PRIMARY KEY (wiki_Id),
CONSTRAINT fk_Perwikitechy FOREIGN KEY (tech_Id)
REFERENCES wikitechy3(tech_Id)
)
click below button to copy the code. By - oracle tutorial - team
FOREIGN KEY: (PARENT TABLE)

- CREATE TABLE statement is used to create a new table in oracle database and ‘wikitechy3’ is the created table name.
- In this statement PRIMARY KEY constraint is used and applied for tech_Id column.
- After that click on the RUN button for executing the queries
- After clicking the run button the table has been created successfully

- INSERT statement is used for inserting the required values in the created columns in the table
- After that click on the RUN button for executing the queries
- After clicking the run button the table has been inserted successfully

- SELECT statement is used to select all the data from created table
- After that click on the RUN button for executing the queries
- After clicking the run button the table has been selected successfully.
FOREIGN KEY: (CHILD TABLE)

- CREATE TABLE statement is used to create a new table in oracle database and ‘wikitechy1’ is the created table name.
- In this statement FOREIGN KEY constraint is used and applied for tech_Id column.
- After that click on the RUN button for executing the queries
- After clicking the run button the table has been created with the foreign key successfully

- INSERT statement is used for inserting the required values in the created columns in the table
- After that click on the RUN button for executing the queries
- After clicking the run button the table has been inserted successfully

- SELECT statement is used to select all the data from created table.
- After that click on the RUN button for executing the queries
- After clicking the run button the table has been selected successfully