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



Oracle foreign key

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 primary key and foreign key
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)

 oracle foreign key create table 1
  • 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
 oracle foreign key insert table 1
  • 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
 oracle foreign key select table 1 output
  1. SELECT statement is used to select all the data from created table
  2. After that click on the RUN button for executing the queries
  3. After clicking the run button the table has been selected successfully.

FOREIGN KEY: (CHILD TABLE)

 oracle foreign key create table 2
  • 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
 oracle foreign key insert table 2
  1. INSERT statement is used for inserting the required values in the created columns in the table
  2. After that click on the RUN button for executing the queries
  3. After clicking the run button the table has been inserted successfully
 oracle foreign key select table 2 output
  1. SELECT statement is used to select all the data from created table.
  2. After that click on the RUN button for executing the queries
  3. After clicking the run button the table has been selected successfully

This tutorial provides an indepth knowledge on the following items such as oracle tutorial , sql tutorial , sql , pl sql tutorial , oracle , pl sql , mysql tutorial , sql tutorial for beginners , learn sql , oracle database tutorial , sql query tutorial , oracle dba tutorial , plsql tutorial , oracle tutorial pdf , oracle pl sql tutorial , oracle sql tutorial , sql tutorial point , oracle tutorial for beginners , learn oracle online free , learn oracle online , learning pl sql programming , learn sql online for free , sql learning online , dba oracle tutorial , oracle sql tutorial advanced , oracle 11g dba tutorial with examples , oracle online learning , oracle learning online , how to learn pl sql , sql coding tutorial , sql learning websites , sql basic learning

Related Searches to Foreign Key Oracle | Foreign Key