SQL FOREIGN KEY
SQL Tutorial » SQL FOREIGN KEY
What is an SQL foreign key?
A foreign key is a key used to link two tables together.
A FOREIGN KEY is one or more or collection of fields in one table, that refers to the PRIMARY KEY in another table.
The table with the foreign key is named child table, and the table with the primary key is named parent table.
SQL FOREIGN KEY on CREATE TABLE
The following SQL creates a FOREIGN KEY on the "ID_column" column when the "my_table_name1" table is created:
ID_column1 int NOT NULL,
Number_column1 int NOT NULL,
ID_column_table2 int,
PRIMARY KEY (ID_column1),
FOREIGN KEY (ID_column_table2) REFERENCES my_table_name2(ID_column_table2)
);
Related subjects:
How to create database phpmyadmin?
SQL create table
PHP select / view data
SQL primary key
SQL alter table
Tags: sql foreign key: constraint failed, as primary key, vs primary key, on delete cascade, multiple tables, cascade, constraint is incorrectly formed, index
postgresql foreign key
mysql foreign key, sql foreign key on delete, add foreign key mysql, alter table add foreign key, primary key and foreign key examples,
What is an SQL foreign key?
How foreign key is implemented in SQL?
Where is foreign key in SQL?
How does a foreign key work?
SQL FOREIGN KEY on ALTER TABLE
To create a FOREIGN KEY constraint on the "ID_column" column when the "my_table_name1" table is already created, use the following SQL:
ADD FOREIGN KEY (ID_column2) REFERENCES my_table_name1(ID_column2);
To allow FOREIGN KEY constraint, and for defining a FOREIGN KEY constraint on multiple columns, use the next SQL syntax:
ADD CONSTRAINT FK_my_table_name2
FOREIGN KEY (ID_column2) REFERENCES Persons(ID_column2);
DROP a FOREIGN KEY Constraint
To drop a FOREIGN KEY constraint, use the following SQL:
DROP FOREIGN KEY FK_name_column2;
sql foreign key: constraint failed, as primary key, vs primary key, on delete cascade, multiple tables, cascade, constraint is incorrectly formed, index postgresql foreign key
mysql foreign key, sql foreign key on delete, add foreign key mysql, alter table add foreign key, primary key and foreign key examples,
What is an SQL foreign key?
How foreign key is implemented in SQL?
Where is foreign key in SQL?
How does a foreign key work?
SQL FOREIGN KEY - sql tutorial
This tool makes it easy to create, adjust, and experiment with custom colors for the web.

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

Find here examples of creative and unique website layouts.

Find here examples of creative and unique website CSS HTML menu.