Вы находитесь на странице: 1из 5

Additional Questions for Lab 14

1. Which of the following statements is likely to have created the Persons table?

create table Persons (


person_id int(11) not null,
name varchar(50) default null,
a. age int(11) default null,
primary key (person_id)
)
create table Persons (
person_id int(11) not null,
b. name varchar(50) default null,
age int(11) default null
)

c. Either (a) or (b).


None of the above.

Use the following statement to answer the NEXT question.

create table experiments


(
num varchar(10) primary key,
resultA int not null,
resultB varchar(10) not null,
resultC int default -1
)

2. What will happen if we execute the following sequence of statements, one after the other?
Assume the table is currently empty and that if a warning is issued, then the statement is
assumed to fail.

insert into experiments (num, resultA, resultB) VALUES("exper1", 100, "res1")


insert into experiments (num, resultA, resultB) VALUES("exper1", 100, "res2")

a. Both will fail.


b. Both will succeed.
c. The first will fail, the second will succeed.
d. The first will succeed, the second will fail.
Please use Pets Table (for questions 79-80) for the NEXT THREE questions below:

3. Which column is most likely the primary key for this table?
a. Name
b. Type
c. BirthDate
d. Price

4. We want to add a new pet squirrel named "Chippy" to this table. Which of the following
queries will add this pet?
a.
INSERT INTO Pets(Name, Type, Sex, Price, Birthdate)
WHERE ('Chippy', 'Squirrel', 'M', '20', '04-05-2005')

b.
INSERT INTO Pets(Name, Type, Sex, Price, Birthdate)
VALUES ('Chippy', 'Squirrel', 'M', '20', '04-05-2005')

c.
INSERT INTO Pets
WHERE Name = 'Chippy' AND Type = 'Squirrel' AND Sex = 'M'
AND Price = 20 AND Birthdate = '04-05-2005'

d.
INSERT INTO Pets
WHERE Name = 'Chippy' OR Type = 'Squirrel' OR Sex = 'M'
OR Price = 20 OR Birthdate = '04-05-2005'
5. What would the following query return?
SELECT COUNT(DISTINCT Weight)
FROM Pets

a. 12
b. 13
c. 8
d. 11

6. What would the following query return?


SELECT COUNT(Weight)
FROM Pets

a. 11
b. 12
c. 8
d. 13

7. What would the following query return?


SELECT MIN(Weight)
FROM Pets

a. 0
b. NULL
c. 7
d. None of the above

Use the following STUDENTS table to answer the NEXT TWO questions.
8. All students having a GPA less than 3.00 have to be removed from the Gradebook
database. Which of the following queries will delete them from the Students table?
a.
delete * from Students
where GPA < 3.00

b.
delete Students
where GPA < 3.00

c.
delete from Students
where GPA < 3.00

d.
select *
delete from Students
where GPA < 3.00

9. Which of the following queries is a correct way to calculate a mean GPA for freshman and
sophomore students?

a.
select sum(GPA)
from Students
where Year = "FR" and Year = "SO"

b.
select avg(GPA)
from Students
where Year = "FR" and Year = "SO"

c.
select sum(GPA)
from Students
where Year = "FR" or Year = "SO"

d.
select avg(GPA)
from Students
where Year = "FR" or Year = "SO"
Solutions to Additional Questions for Lab 14
1. The answer is (a). Option (b) does NOT create a table since primary key field is missing.
2. The answer is (d). The second query will fail because num will not be a unique entry.
3. The answer is (a) Since it is the only column with unique entries in it.
4. The answer is (b). Option (a) has a typo in it.
5. The answer is (c). Count (Distinct …) does not take into account the NULL value.
6. The answer is (a). SQL COUNT function does not take into account the NULL value.
7. The answer is (b). SQL MIN function does not take into account the NULL value.
8. The answer is (c). Other choices have syntax errors.
9. The answer is (b).

Вам также может понравиться