+ 1

Can someone explain FOREIGN KEY?

And how make one on CREATE TABLE and ALTER TABLE. I am lost here.

6th Aug 2016, 3:28 PM
Juan Manuel Espinosa
Juan Manuel Espinosa - avatar
3 Antworten
+ 2
Foreign key represents relation between two tables.A foreign key is a column whose values are derived from primary key of some other table. The table in which the foreign key is defined is called foreign table or digital table .
7th Aug 2016, 1:51 PM
k JayaprakashReddy
k JayaprakashReddy - avatar
+ 1
A FOREIGN KEY in one table points to a PRIMARY KEY in another table. The FOREIGN KEY constraint is used to prevent actions that would destroy links between tables, it also prevents invalid data from being inserted into the foreign key column, because it has to be one of the values contained in the table it points to. Create example: CREATE TABLE Orders ( O_Id int NOT NULL, OrderNo int NOT NULL, P_Id int, PRIMARY KEY (O_Id), FOREIGN KEY (P_Id) REFERENCES Persons(P_Id) ) Alter table example: ALTER TABLE Orders ADD FOREIGN KEY (P_Id) REFERENCES Persons(P_Id)
7th Aug 2016, 5:26 AM
Nathan “Grimston” Pipes
Nathan “Grimston” Pipes - avatar
0
la foreign key garantiza la integridad referencial.
10th Aug 2016, 4:46 AM
JOSE RODRIGO VELOSA GIL
JOSE RODRIGO VELOSA GIL - avatar