1. Learn
  2. /
  3. Courses
  4. /
  5. Hierarchical and Recursive Queries in SQL Server

Connected

Exercise

Create the parts list

The first step in creating a bill of material is to define a hierarchical data model. To do this, you have to create a table BillOfMaterial with the following fields:

The BillOfMaterial table describes the following hierarchy:

Your task is to define the field PartID as primary key, to define the field Cost, and to insert the following to records into the table:

  • Component: SUV, Title: BMW X1, Vendor: BMW, ProductKey: F48, Cost: 50000, Quantity: 1
  • Component: Wheels, Title: M-Performance 19/255, Vendor: BMW, ProductKey: MKQ134098URZ, Cost: 400, Quantity: 4

Instructions

100 XP
  • Define PartID as PRIMARY KEY of type INT.
  • Define Cost of type INT and not to be NULL.
  • Insert the root element SUV as described in the context section.
  • Insert the entry Wheels as described in the context section.