Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

1.

Consider the following MySQL table:Frog


ID [PK]
Name
Age
1
Pom
3
2
Pi
3
3
Al
2
4
Ed
4
5
Wu
1
6
Stu
3
Write MySQL statements to do the following:a) Display all information pertaining to frogs.

b) Display all information pertaining to frogs sorted alphabetically by age in ascending order.

c) Display the name of frogs that are aged 2 or less.

d) Display all information pertaining to frogs who have a name beginning with P.

e) Display how many frogs member have a different age.

f)

Display all information pertaining to frogs whose age is 3 or more or who are called Al.

g) Change Wus name to Putty,

h) Add the frog Leo who is 300 years old.

i)

Create the table with appropriate domains.

SQL Surgery

2. Consider the following MySQL tables:Frog


ID[PK]
1
2
3
4
5
6

Name
Pom
Pi
Al
Ed
Wu
Stu

Age
3
3
2
4
1
3

ID [FK]
1
1
2
3
4
4
5

Operations
Notes
Success
Success
Died
Died
Partial Success
Success
Died

a) Write a MySQL query to show all the operation notes with the name of the corresponding frog
using a Natural Join and a theta equi-join.

b) Stu the Frog has not had an operation. What kind of join would include Stu the Frog as well as
showing all the operation notes of all the other frogs?

c)

Write an SQL query to show the name and operation notes of all the frogs, but also include Stu
and show that he has had no operations

d) Are Frog and Operations are weak or strong entities? Explain why.

3. Consider the following MySQL statements that generate a single table database and populate it
with data.
CREATE TABLE HospitalAppointments(
PatientID Integer, PatientName TEXT, OpticianID Integer, OpticianName
TEXT, Appointment1 DATE, Notes1 TEXT, Appointment2 DATE, Notes2 TEXT,
PRIMARY KEY (PatientID, SurgeonID)
);
This table is not in 3NF. State why, and design code for new MySQL table(s) that are in 3NF.

SQL Surgery

You might also like