SQL FOREIGN KEY

A FOREIGN KEY in one table points to a PRIMARY KEY in another table.
The FOREIGN KEY constraint also prevents that invalid data form being inserted into the foreign key column, because it has to be one of the values contained in the table it points to.
The foreign key can be used to cross-reference tables


SYNTAX :
SELECT foreign key("column_name")
FROM "table_name"



There are two tables given below from which concept of foreign can be understood.

table 'customers'

id

name

age

city

bill

1Tom34Paris5300
2Jhony51London 400
3Ram64Delhi20000.7
4Simon23Portland32.65

table 'orders'

O_Id OrderNo P_Id
1 95 3
2 78 3
3 562
4 62 1



Online Execute/Compile