lab8

advertisement
Lab 8 – SQL Exercises
Instruction for lab 8 – please copy lab8 folder to your personal AFS folder. Then start
your lab from there. Keep all your results under lab8. Some exercise may generate no
results, such as question 4.
1.
(1). Create a table called Cust with a customer number as a fixed length character string
of 3, an address with a variable-length character string of up to 20, and a numeric balance
of five digits.
(2). Put values in the table with INSERT INTO .. VALUES. Use the form of INSERT
INTO .. VALUES that requires you to have a value for each attribute; therefore, if you
have a customer number, address, and balance, you must insert three values with
INSERT INTO VALUES.
(3). Create at least five tuples (rows in the table) with customer numbers 101 to 105 and
balances of 200 to 2000.
(4). Display the table with a simple SELECT.
(5). In the display of your Cust table, does your balance field show up with a $ symbol? If
not, alter your table design so that a $ symbol is added to each of the balances.
f. Show the balances for customers with customer numbers 103 and
104.
(6). Add a customer number 90 to your Cust table. Is it lined up with the rest of the
customer numbers? Why or why not? If not, line it up with the rest of the customer
numbers.
(7). Show a list of the customers in balance order (high to low), using ORDER BY in
your SELECT. (Result: Five tuples or however many you created.)
2. From the Student table, display the student names, classes, and majors for freshmen or
sophomores (class <= 2) in descending order.
3. From your Cust table, show a list of only the customer balances in ascending order
where balance > 400. (You can choose some other constant or relation if you want, such
as balance <= 600.) The results will depend on your data.
4. (1) Display the student name and student number of students who are juniors
(2) Display all the junior student names and numbers in descending order by name
5. What output will the following query produce?
SELECT COUNT (class)
FROM Student
WHERE class IS NULL;
Why do you get this output?
Download