Assignment 3 - Al Akhawayn University

advertisement
Al Akhawayn University
School of Science and Engineering
CSC 3326 Database Systems
Individual Homework assignment 3
(Deadline 8th April, 12:30, only paper version, NO EMAIL)
Question 1 (10 pt/35)
a. What are the three basic data functions are provided by SQL, and what are their basic SQL
commands?? (1PT)
b. Explain the data types text and binary of SQL Server and give usage example? (1PT)
c. What is the role of cursor in Embedded SQL? ? (1PT)
For the following questions in this section write the SQL statements and also the results; Use for
questions d - h the Northwind database in SQL Server
d. List the number of employees who have a null value in the reportsto column in the employees
table. ? (1PT)
e. Calculate the average unit price of all products in the products table. ? (1PT)
f.
Group products according to their product ID and calculates the total quantity ordered from the
table order details. ? (2PT)
g. Give a SQL statement and result for each group of products from the order details table that has
orders of 30 or more units. ( 1PT)
h. List all customers in the orders tables who placed orders on the most recent recorded day (2PT)
Question 2 (20/35)
1. Problem in textbook page 299, answer all questions 1-20 (1PT each )
Question 3 (5/35)
Explain each command of this embedding SQL program in C
char SQLSTATE[6];
EXEC SQL BEGIN DECLARE SECTION
char c_sname[20]; short c_minrating; float c_age;
EXEC SQL END DECLARE SECTION
c_minrating = random();
EXEC SQL DECLARE sinfo CURSOR FOR
SELECT S.sname, S.age FROM Sailors S
WHERE S.rating > :c_minrating
ORDER BY S.sname;
do {
EXEC SQL FETCH sinfo INTO :c_sname, :c_age;
printf(“%s is %d years old\n”, c_sname, c_age);
} while (SQLSTATE != ‘02000’);
EXEC SQL CLOSE sinfo;
Download