Sunteți pe pagina 1din 12

MIS331 – ASSIGNMENT 3

Due: Oct. 31 (upload to D2L before class)

*Submit a single PDF document, with your name on the cover page.

*The naming of the submission follows the format “Assignment 3_FirstName_LastName.pdf”.

AY 2018/19 – SEM 1

Student Name: Linda Zhu


ASSIGNMENT 3 (25%)
MIS331 Database Management Systems· SEM1·AY2018/2019

SQL I

Multiple Choice (7%)

1. is a set of commands used to control a database, including security.


A) DML
B) DDL
C) DCL
D) DPL

2. DDL is typically used during which phase of the development process?


A) Implementation
B) Physical design
C) Analysis
D) Evaluation

3. The main concept of relational databases was published in 1970 by:


A) Itzak Ben-Gan.
B) Hoffer.
C) Mills.
D) E.F.Codd.

4. The first in a series of steps to follow when creating a table is to:


A) identify columns that must be unique.
B) identify each attribute and its characteristics.
C) create an index.
D) identify columns that must be null.

5. Given a table named store with 5 fields: store_id, address, city, state, zipcode, why
would the following insert command not work?

insert into store values ('234 Park Street');

A) It would work just fine.


B) You must specify the fields to insert if you are only inserting some of the fields.
C) There is no table keyword.
D) Insert into should be INSERT to.

6. Indexes are created in most RDBMSs to:


A) provide a quicker way to store data.
B) decrease the amount of disk space utilized.
C) provide rapid random and sequential access to base-table data.
D) increase the cost of implementation.

1
7. In an SQL statement, which of the following parts states the conditions for row
selection?
A) Select
B) From
C) Where
D) Group By

8. What does the following SQL statement do?

Select * From Customer Where Cust_Type = "Best" ;

A) Selects all the fields from the Customer table for each row with a customer labeled
"Best"
B) Selects the "*" field from the Customer table for each row with a customer labeled
"Best"
C) Selects fields with a "*" in them from the Customer table
D) Selects all the fields from the Customer table for each row with a customer labeled
"*"

9. What result set will the following query return?

Select Item_No
from Order_V
where quantity > 10;

A) The Item_No of all orders that had more than 10 items


B) The Order_Id of all orders that had more than one item
C) The Order_Id of all orders that had more than 10 items
D) The Item_No of all orders that had 10 or more items

10. What does the following SQL statement do?

Delete from Customer_T


where state = 'HI';

A) Deletes all records from customer_t where the state is equal to HI


B) Removes the Customer_T table from the database
C) Deletes all records from the Customer_T table
D) Doesn't delete anything because of a syntax error

11. What does the following SQL statement do?

Update Product_T
Set Unit_Price = 775
Where Product_ID = 7

A) Changes the price of a unit called Product_T to 7


B) Changes the unit price of Product 7 to 775

2
C) Changes the length of the Unit_Price field to 775
D) Updates the Product_T table to have a unit price of 775

12. INSERT INTO is an example of code.


A) DDL
B) DML
C) DCL
D) TIO

13. Referential Integrity Constraints are generally established between:


A) Referential and Integrity keys.
B) Primary and Secondary keys.
C) Primary and Foreign keys.
D) Foreign and Domestic keys.

14. The SQL command defines a logical table from one or more tables or views.
A) create table
B) alter table
C) create view
D) create relationship

3
Problem I (12%)

15. Write the SQL commands for creating each of the relations shown below. Specify the
primary key(s) and foreign key(s) (if necessary) constrains for each relation in the
commands. (9%)

Assume the following attribute data types:

StudentID (integer, primary key)


StudentName (25 characters)
FacultyID (integer, primary key)
FacultyName (25 characters)
CourseID (8 characters, primary key)
CourseName (15 characters)
DateQualied (date)
SectionNo (integer, primary key)
Semester (7 characters)

4
For each relation (1.5%):
- Create the relation in your workspace using MySQL Workbench, e.g., UA
ID_workspace, using your command (0.5%)
- Copy your command to the submission document (0.5%)
USE xiaoyizhu_workspace;

CREATE TABLE Student_T


(StudentID integer PRIMARY KEY,
StudentName Varchar(25));

CREATE TABLE Faculty_T


(FacultyID integer PRIMARY KEY,
FacultyName Varchar(25));

CREATE TABLE Course_T


(CourseID Varchar(8) PRIMARY KEY,
CourseName Varchar(15));

CREATE TABLE Qualified_T


(FacultyID integer,
CourseID varchar(8),
DateQualified date,
CONSTRAINT Qualified_PK PRIMARY KEY (FacultyID, CourseID),
CONSTRAINT Qualified_FK1 FOREIGN KEY (FacultyID) REFERENCES Faculty_T(FacultyID),
CONSTRAINT Qualified_FK2 FOREIGN KEY (CourseID) REFERENCES Course_T(CourseID));

CREATE TABLE Section_T


(SectionNo integer PRIMARY KEY,
Semester varchar(7),
CourseID varchar(8),
CONSTRAINT Section_FK FOREIGN KEY (CourseID) REFERENCES Course_T(CourseID));

CREATE TABLE Registration_T


(StudentID integer,
SectionNo integer,
CONSTRAINT Registration_PK PRIMARY KEY (StudentID, SectionNo),
CONSTRAINT Registration_FK1 FOREIGN KEY (StudentID) REFERENCES Student_T(StudentID),
CONSTRAINT Registration_FK2 FOREIGN KEY (SectionNo) REFERENCES
Section_T(SectionNo));

Insert into Student_T Values


(38214,'Letersky');
Insert into Student_T Values
(54907,'Altvater');
Insert into Student_T Values
(66324,'Aiken');
Insert into Student_T Values
(70542,'Marra');

Insert into Faculty_T Values


(2143,'Birkin');
Insert into Faculty_T Values
5
(3467,'Berndt');
Insert into Faculty_T Values
(4756,'Collins');

Insert into Course_T Values


('ISM 3113','Syst Analysis');
Insert into Course_T Values
('ISM 3112','Syst Design');
Insert into Course_T Values
('ISM 4212','Database');
Insert into Course_T Values
('ISM 4930','Networking');

Insert into Qualified_T Values


(2143,'ISM 3112','2005-09-00');
Insert into Qualified_T Values
(2143,'ISM 3113','2005-09-00');
Insert into Qualified_T Values
(3467,'ISM 4212','2012-09-00');
Insert into Qualified_T Values
(3467,'ISM 4930','2013-09-00');
Insert into Qualified_T Values
(4756,'ISM 3113','2008-09-00');
Insert into Qualified_T Values
(4756,'ISM 3112','2008-09-00');

Insert into Section_T Values


(2712,'I-2015','ISM 3113');
Insert into Section_T Values
(2713,'I-2015','ISM 3113');
Insert into Section_T Values
(2714,'II-2015','ISM 4212');
Insert into Section_T Values
(2715,'II-2015','ISM 4930');

Insert into Registration_T Values


(38214,2714);
Insert into Registration_T Values
(54907,2714);
Insert into Registration_T Values
(54907,2715);
Insert into Registration_T Values
(66324,2713);

Select * from Student_T;


Select * from Faculty_T;
Select * from Course_T;
Select * from Qualified_T;
Select * from Section_T;
Select * from Registration_T;

DESCRIBE Student_T;
6
DESCRIBE Faculty_T;
DESCRIBE Course_T;
DESCRIBE Qualified_T;
DESCRIBE Section_T;
DESCRIBE Registration_T;

- Take a screenshot after displaying the information for the relation’s columns
(using DESCRIBE <tablename>) (0.5%)

7
16. Write the SQL commands for inserting the following data into the COURSE relation.
(3%)

CourseID CoureName
ISM 3113 Syst Analysis
ISM 3112 Syst Design
ISM 4212 Database
ISM 4930 Network

- Execute your commands in your workspace using MySQL Workbench (1%)


- Copy your commands to the submission document (1%)
Insert into Course_T Values
('ISM 3113','Syst Analysis');
Insert into Course_T Values
('ISM 3112','Syst Design');
Insert into Course_T Values
('ISM 4212','Database');
Insert into Course_T Values
('ISM 4930','Networking');

- Display the data of the COURSE relation after insertion


(using SELECT * FROM COURSE) (1%)

8
Problem 2 (6%)

17. Based on the classicmodels on our MySQL Server, what SQL queries would you use to
retrieve the following information?

I. Retrieve all values from the customerName and city attributes in the customers
table (1%)
II. Retrieve all records in the orders table (1%)
III. Retrieve all the orders that have been cancelled (1%)
IV. Retrieve all the orders where the corresponding customerNumber is greater than
100 (1%)
V. Retrieve all the employees whose jobTitle is not “Sales Rep” (1%)
VI. Retrieve the list of job titles for employees (1%)

For each question:


- Execute your command in MySQL Workbench
- Copy your command to the submission document
I. SELECT customerName, city
FROM classicmodels.customers;
II. SELECT * FROM classicmodels.orders;
III. SELECT * From classicmodels.orders where status='Cancelled';
IV. SELECT * From classicmodels.orders
where customerNumber>100;
V. SELECT * FROM classicmodels.employees where jobTitle!='Sales Rep';
VI. SELECT DISTINCT jobTitle FROM classicmodels.employees;

- Take a screenshot after displaying the result of query


I.

II.

9
III.

IV.

V.

1
0
VI.

1
1

S-ar putea să vă placă și