题目:
一.单项选择
| 1. |
| With respect to a relational table, what is a key? |
|
| (a) A minimal subset of columns that uniquely identifies a row in the table |
| 2. |
| Which of the following is true about the number of primary keys and alternate keys with respect to a table? |
|
| (a) There can be many primary keys, but only one alternate key. |
| 3. |
| An insertion operation will _____ if the insertion violates the uniqueness property of a key. |
|
| (a) succeed with warning |
| 4. |
| An insertion operation will _____ if the inserted primary key has a |
|
| (a) succeed with warning |
| 5. |
| For two tables to be union compatible, corresponding columns from each table should have which of the following? |
|
| (a) different domains |
| 6. |
| In the relational model, which of the following is true about the data type of a column? |
|
| (a) It need not be atomic and it cannot be an abstract data type. |
| 7. |
| What is an alternate key? |
|
| (a) Any key that is not a primary key |
| 8. |
| What does a projection operation do? |
|
| (a) It extends the number of columns in a table. |
| 9. |
| The result of a set difference operation r - s will be |
|
| (a) tuples in r after deducting their values by the corresponding values in the tuples in s |
| 10. |
| Which of the following is true about primary keys and foreign keys holding |
|
| (a) A primary key can hold a |
| 11. |
| In contrast to _____ tables, a view refers to _____. |
|
| (a) base, a virtual table |
| 12. |
| When removing a table from the schema, using the |
|
| (a) remove the table and all references to it |
| 13. |
| In a transaction, |
|
| (a) all updates (including inserts, deletes, modifications) of a transaction are about to be made permanent in the database |
| 14. |
| Which of the following is true about the physical storage of tables defined by views? |
|
| (a) Extra physical storage is needed for storing the tables defined by views, only if views define additional non-existing columns. |
| 15. |
| Which of the following SQL commands can be used to change, add, or drop column definitions from a table? |
|
| (a) |
| 16. |
| Which of the following SQL commands can be used to destroy and remove a table from the schema? |
|
| (a) |
| 17. |
| In SQL, which of the following operators are used to check for set membership in a |
|
| (a) |
| 18. |
| In SQL, the results of a _____ statement can be used to process a _____ statement. |
|
| (a) |
| 19. |
| In a transaction, a |
|
| (a) roll all the updates (including inserts, deletes, modifications) of an aborted transaction into the database |
| 20. |
| When a string whose length is strictly less than |
|
| (a) padding the end of the string with spaces to length |
|
|
二.问答类
Database Systems PracticalAnswer the following questions: 1. Let the following relational tables be given: R = (A, B, C) and S = (D, E, F) where A, B, C, D, E, and F are the attributes (columns). Write the SQL statements that will express each of the queries given below: 1. ΠA(R) 2. σB = 13(R) 3. ΠA,B(R
2. Given relation r as:
3. Given relation s as:
4. Provide the results of the following operations. If an operation cannot be performed, state the reasons. Do not write the equivalent SQL statements. 1. σdept = 'Admin' AND project <> 'Audit'(r) 2. r U s 3. Πdept(r) - Πdept(s) 5. Consider the following Mail Order database:
6.
7.
8.
9. In the table ORDERS above, specify in SQL the requirements that: 1. Received date cannot be undefined and that 2. the Shipped date, if it is not NULL, should be greater than the Received date. 10. Translate in SQL the following queries. Note: The "Received" column in ORDERS table above refers to when the order is received by the system (and not when the ordered items are received by the customer). 1. Get the part number of parts that cost between 10 and 25 dollars. 2. For each part sold in 1998, list the total quantity sold in 1998. Sort your results in ascending order by the total billed price for each part for that year. Parts are considered sold when an order is received. The BilledPrice column in the Invoice table indicates the total price billed for that part (i.e., quantity sold multiplied by unit price minus discount, if any). 3. Get those parts that were not sold in 1998. A part is considered sold when an order is received. 11. Given the following schema definitions, specify in SQL2 the referential integrity constraint on the EMPLOYEE relation that will prevent an employee from being assigned to a non-existent department. 12. create table EMPLOYEE 13. (id id_dom primary key deferrable, 14. name name_dom, 15. salary salary_dom, 16. dname dept_name_dom 17. ); 18. 19. create table DEPARTMENT 20. (name dept_name_dom primary key deferrable, 21. mgrid id_dom foreign key references emp(id) deferrable, 22. budget budget_dom 23. ); |
|
|
|
我交的答案,很可能有错,等老帅评讲后,我再给出标准答案:
/*********************PARTI*********************/
Answer for Multiple-choice:
1 ~ 5:ABACC
6 ~10:DDADC
11~15:AABCD
16~20:ABBCD
/*********************PARTII*********************/
Answer for Practical:
1.
1)SELECT A
FROM R
2)SELECT B
FROM R
WHERE B=’ 13’
3)USE Pubs
SELECT A,B FROM R INNER JOIN S
ON R.C=S.D
4.
1) ename project dept
Kasper Spreadsheet Admin
Mohan Spreadsheet Admin
Lin Forecast Admin
Lin Spreadsheet Admin
2) ename project dept
Kasper Forecast Accounting
Kasper Audit Accounting
Kasper Spreadsheet Admin
Mohan Forecast Accounting
Mohan Audit Admin
Mohan Spreadsheet Admin
Lin Forecast Admin
Lin Audit Admin
Lin Spreadsheet Admin
3)这里将不会返回任何值,因为语句的意思是取出列dept中属于r但不属于s的所有值,显然不存在这样的值。
9.
1)ALTER TABLE ORDERS
ALTER COLUMN Received
datetime NOT NULL
2)ALTER TABLE ORDERS
CONSTRAINT Shipped1 UNIQUE(Shipped)
CONSTRAINT Shipped2 CHECK(Shipped = “” OR Shipped > Received)
10.
1) SELECT Pno
FROM PART
WHERE UnitPrice > 10 AND UnitPrice <25
2) SELECT Ono,Qty,BilledPrice
FROM INVOICE
WHERE Ono IN (SELECT Ono
FROM ORDERS
WHERE Received LIKE "%1998")
COMPUTE SUM(Qty)
ORDER BY BilledPrice ASC
3) SELECT Ono,Pno,Qty,BilledPrice
FROM INVOICE
WHERE Ono NOT IN (SELECT Ono
FROM ORDERS
WHERE Received LIKE "%1998"))
11.
CREATE TABLE EMPLOYEE(
id_dom NUMERIC(20) NOT NULL,
name_dom VARCHAR(40) NOT NULL,
salary_dom VARCHAR(40) NOT NULL,
dept_name_dom VARCHAR(40) NOT NULL,
PRIMARY KEY (id_dom));
CREATE TABLE DEPARTMENT(
dept_name_dom VARCHAR(40) NOT NULL,
id_dom NUMERIC(20) NOT NULL,
budget_dom VARCHAR(40) NOT NULL,
PRIMARY KEY (dept_name_dom),
FOREIGN KEY (id_dom) REFERENCES EMPLOYEE (id_dom));