SQL FOREIGN KEY constraint
The FOREIGN KEY in one table points to the PRIMARY KEY in another table.
Let us explain foreign keys through an example. Please look at the following two tables:
"Persons" table:
| P_Id | LastName | FirstName | Address | City |
|---|---|---|---|---|
| 1 | Hansen | Ola | Timoteivn 10 | Sandnes |
| 2 | Svendson | Tove | Borgvn 23 | Sandnes |
| 3 | Pettersen | Kari | Storgt 20 | Stavanger |
"Orders" table:
| OrderNo | P_Id | |
|---|---|---|
| 77895 | 3 | |
| 44678 | 3 | |
| 22456 | 2 | |
| 24562 | 1 |












![Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]](https://img.php.cn/upload/course/000/000/035/5d27fb58823dc974.jpg)









