-- wrong code -- foreign key -- The FOREIGN KEY constraint is used to prevent actions that would destroy links between tables. -- A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the PRIMARY KEY in another table. -- The table with the foreign key is called the child table, and the table with the primary key is called the referenced or parent table. create table Person(PersonID int Primary key, LastName varchar(255),FirstName varchar(255), Age int); insert into Person(PersonID, LastName, FirstName, Age)values(1, "Hansen","Ola",30); insert into Person(PersonID, LastName, FirstName, Age)values(2,"Svedson","Tov",23); insert into Person(PersonID, LastName, FirstName, Age)values(3,"Zenitsu","YellowStone",20); select * from Person; CREATE TABLE orders(OrderId int NOT NULL, OrderNumber int NOT NULL, PRIMARY KEY (OrderId), FOREIGN KEY (PersonId) REFERENCES Person(PersonId); insert into orders(OrderId, OrderNumber,PersonID)values(1,77895,3); select * from orders;
To embed this project on your website, copy the following code and paste it into your website's HTML: