Documente Academic
Documente Profesional
Documente Cultură
Customers
CustomerID Name
(Int) (nVarChar(50))
1 John Nguyen
2 Bin Laden
3 Bill Clinton
4 Thomas Hardy
5 Ana Tran
6 Bob Carr
Orders
OrderI CustomerID ProductName DateProcessed
D (Int) (nvarchar(50)) (datetime)
(Int)
1 2 Nuclear Bomb ‘2002-12-01’
2 3 Missile ‘2000-03-02’
3 2 Jet-1080 ‘2004-08-03’
4 1 Beers ‘2001-05-12’
5 4 Asian Food ‘2002-10-04’
6 6 Wine ‘2002-03-08’
7 5 Milk ‘2002-05-02’
Constraints
a. Apply the Primary Key Constraint for the “ID” columns of the 2 tables
b. Apply the Foreign Key Constraint in the Orders table.
c. Apply the Check Constraint to the DateProcessed column so that the date
is within ‘1970-01-01’ – ‘2005-01-01’
d. Apply Unique Constraint to the CustomerName column of Customers
2. Create a new table called “Processed Orders” and populate the new table with
the data selecting from Orders table Where DateProcessed is earlier than ‘2002-
10-05’.
3. Create a view named vw_All_Orders that merges the two data set from Orders
and ProcessedOrders into one data set. Show all the orders in 2 tables.
4. Create a view named vw_Customer_Order that shows all the orders with the
following colums:
OrderID,CustomerName,ProductName,DateProcessed,Status
Business rules:
If CustomerName is a null value “New Customer” is returned
If DateProcessed is later than current date return “Pending”, if DateProcessed
is ealier return “History” in Status colum.
Tips:
a. Using Case When ...Then statement in the view
b. Using Getdate() function to get the current date time
(Hints: Based on the data supplied and your knowledge about various kind of joins
guess the results then after each select compare it with your guessing to check if what
you understand is correct. You also use As keyword or alias in the queries)
Tips:
• Create an audit table “aud_Orders” with the same colums as in the Orders
table and 1 more colum AuditDateTime (which will record the date time of
deletion)