Aan de slagGa gratis aan de slag

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:

  1. Andrew Anderson bought an iPhone XS for 1000
  2. 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

Deze oefening maakt deel uit van de cursus

Hierarchical and Recursive Queries in SQL Server

Cursus bekijken

Oefeninstructies

  • 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 for 1000.
  • Insert a new order for Sam Smith: MacBook Pro for 1800.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

-- 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;
Code bewerken en uitvoeren