0% found this document useful (0 votes)
8 views7 pages

For The Submission of Your Work

Uploaded by

nhanvthe180537
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

For The Submission of Your Work

Uploaded by

nhanvthe180537
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1 of 7 Paper No: 1

For the submission of your work:


- Create a folder named RollNo_Name_DBI202_PaperNo, e.g.
se01245_LongNT_DBI202_01. All file created will be located in the above folder.
- For each question, you are required to write a database script. Create a file with the name
corresponding to the index of the question. For example, for question 1, we will create a file
named Q1.sql and create a file Q2.sql for question 2. These files contain only the required
workflow commands that do not include other commands including the database context
switch (not including use [database name]).
- On completion, import your work by browsing to the above folder.

From the 2nd question, you should use the database provided in the DBscript.sql file which has the
following database diagram. Please, run the provided script to create tables and insert data into your
database.
2 of 7 Paper No: 1

Question 1:
Create one database and then write SQL statements to create all tables derived from the
ERD given in Picture 1.1. Those tables have to locate under the database that you have just
created with appropriate attributes, primary keys and foreign keys.

NOTE that when creating the SQL commands as request, you MUST keep the name of
tables, relationship and attributes and data type of attributes as SAME as given in the above
ERD.
Attributes have written with underline are Primary Key of each entity.
When submitting the responses for this question, submit only SQL statements for creating
tables with corresponding keys and foreign keys. Do not use “create database” or “use
database_name” statements in your submission.

Picture 1.1
Question 2:
Write a query to display all customers who are ‘Consumer’ and are from Arlington city as
follows:
3 of 7 Paper No: 1

Picture 2.1
Question 3:
Write a query to display all customers having CustomerName starting with B and placed
orders in December 2017. Display the result by descending order of Segment and then by
ascending order of CustomerName.

Picture 3.1
Question 4:
Write a query to display SubCategoryID, SubCategoryName and the corresponding number
of products (NumberOfProducts) in each sub-category having the number of products
greater than 100, by descending order of NumberOfProducts.
4 of 7 Paper No: 1

Picture 4.1
Question 5:
Write a query to display ProductID, ProductName, Quantity of all products which have the
highest Quantity in one order.
5 of 7 Paper No: 1

Picture 5.1
Question 6:
Write a query to display CustomerID, CustomerName and the number of orders
(NumberOfOrders) of customers who have the highest number of orders.
6 of 7 Paper No: 1

Picture 6.1
Question 7:
Display 5 products with the highest unit prices and 5 products with the smallest unit prices as
follows:

Picture 7.1
Question 8:
Write a stored procedure named CountProduct to calculate the number of different products
in an order with OrderID (nvarchar(255)) is input parameter and the NbProducts (int) is the
output parameter of the procedure.

For example, when we execute the following code, the result should be 1:
declare @t int
exec CountProduct 'CA-2014-100391', @t output
print @t
Question 9:
Create a trigger InsertProduct which will be activated by an insert statement into the Product
table. The trigger will display the ProductName and the SubCategoryName of the products
which have just been inserted by the insert statement.

For example, when we run:


insert into Product(ProductName, UnitPrice, SubCategoryID)
7 of 7 Paper No: 1

values ('Craft paper', 0.5, 3)


The result should be as follows:

Picture 9.1
Question 10:
Insert the following information:
- A category named 'Sports' into table Category
- A subcategory named 'Tennis' and a subcategory named 'Football' into table SubCategory,
both these two subcategories are subcategories of Category 'Sports'

You might also like