Inserting data to person and order history
Next, you will insert data into the two newly generated tables, Person
and History
. Enter the following orders:
- Andrew Anderson bought an iPhone XS for 1000
- Sam Smith bought a MacBook Pro for 1800
When inserting the customers and their orders into the tables make sure that:
- the primary key is unique
- you use the correct foreign key
This exercise is part of the course
Hierarchical and Recursive Queries in SQL Server
Exercise instructions
- Insert new data for the person with
ID=1
, Andrew Anderson. - Insert new data for the second person with
ID=2
, Sam Smith. - Insert a new order for Andrew Anderson:
iPhone XS
for1000
. - Insert a new order for Sam Smith:
MacBook Pro
for1800
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
-- Insert new data into the table Person
___ INTO ___
___ (1,___,'Anderson','Union Ave 10','New York','1986-12-30');
___ ___ Person
VALUES (___,___,___,'Flushing Ave 342','New York','1986-12-30');
-- Insert new data into the table History
___ ___ History
___ (1,'iPhone XS',___,___);
INSERT ___ ___
___ (___,'MacBook Pro',1800,___);
SELECT *
FROM History;