Textbook Chapter 62-66

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Harvey James

I completed the Codecademy SQL course:


Harvey James

Chapter 62:
Q1: Age, Blood type, Gender
Q2: Time of appointment dentist assigned to it
Q3: Yes because it is unique among everyone in the UK.
Q4: Yes because the word entity has the foreign key Nurse and Patient
Q5: a)
Product ProductComp Component

b)

Customer Order Product

Exercises:
1. a) House Address, House Price, House type, Buyer name, Date and Time of viewing
b)
Property (address, BedroomNum, Type, AskingPrice)
Vendor (name, address, telephone)
Buyer (name, telephone, address, type, lower/upper limit)
Viewing (Address, Price, Type, BuyerName, Date/Time)
c)
Property Viewing Vendor Buyer

2. a)
Book Loan Member

b) A primary key which consists of more than one attribute is called a composite primary key
c) A foreign key is an attribute that creates a join between two tables. It is the attribute that
is common to both tables and the primary key in one table is the foreign key in the table to
which it is linked
Harvey James

3. a) ExampaperID
b) Coursestaking(CandidateNumber, Firstname, Surname, courseID, subject)
c)
ExamPaper CourseTaking

d) Results(ExampaperID, Marks, TotalMarks, Exampaperweighing)

Chapter 63:
Q1: It can be hard to create and manage when you have large amounts of products and
components. It is not practical for human users.
Q2:
Product

ProductID ProductName CostPrice SellingPrice


123 Small Monkey 2.50 5.95
156 Pink Kitten 3.10 6

ProductComp

Product ID CompID CompQty


123 ST01 30
156 ST01 45
123 G56 2
123 FF77 0.3
156 G120 2
156 FF88 0.35
156 S34 1

Component

CompID CompName SupplierID SupplierName


ST01 Stuffing ABC ABC Ltd
G56 Eye(small) BH glass Brown and Hill
FF77 BrownFur Fine Fur Fine Toys Ltd
G120 Eye(medium) XYZ Glass XYZ Ltd
FF88 PinkFur Fine Fur Fine toys Ltd
S34 SoundBox Ping Toys Ping and co

Q3: (ProductID, CompID)


Harvey James

Exercises:
1. a) ‘CatalougeNo’ as it is unique
b) It contains repeating attributes
SongMusic
c) Compact Disk

CD-Track Artist

d) i) CompactDisk(CatalougeNo, Title, recordcompany, Type)


ii) SongMusic(SongMusicID, Title, ComposerName)
iii) Artist(ArtistID, ArtistName)
iv) CD-Track(TrackNo, TrackDuration)
e) SELECT tracknumbers, SongMusicID, ArtistID FROM SongMusic, Artist, CD-Track,
CompactDisk
WHERE (Artist.ArtistID = SongMusic.ArtistID) AND (SongMusic.SongMusicID = CD-
Track.SongMusicID) AND (CD-Track.CatalogueNo = CompactDisk.CatalogueNO) AND
(CompactDisk.CatalogueNO =15438)
2. a)

Student StudentCourse Course Teacher

b) All attributes are dependent on the key and only the key

Chapter 64:
Q1: SELECT * FROM CD
WHERE (RecordCompany = “ABC” OR RecordCompany = “GHK”) AND DatePublished
BETWEEN #01/01/2014 AND #01/01/2015
#will return CD14356, CD19998, CD25364, CD77233
Q2: SELECT Song.SongTitle, Artist.ArtistName, Song.MusicType
From Song, Artist
WHERE (Song.ArtistID = Artist.ArtistID) AND (Artist.ArtistName = “JJ” Or Artist.ArtistName =
“Rappat”)
ORDER BY ArtistName, SongTitle DESC
Harvey James

Exercises:
1. a)
Customer Product

Order OrderLine

b) Product(ProductID, ProductDesc, Quantity)


Customer(CustomerID, CustomerName, CustomerAddress, CustomerTelephoneNumber)
Order(ABCOrderNo, CustomerOderNo, Dispatched, LineNo)
OrderLine(LineNo, ProductID, Quantity, ProductRef)
c) SELECT Customer.CustomerName, Order.OrderDispatched, Order.ABCOrderNO
FROM Order, Customer
WHERE (Customer.CustomerID = Order.CustomerOrderNo) AND (Order.OrderDispatched =
“Yes”)
ORDER BY ABCOrderNo DESC
2. a)
Pupil PupilTrip Trip Teacher

b) i) SELECT Pupil.PupilSurname, Pupil.PupilFirstName


FROM Pupil, PupilTrip
WHERE (Pupil.PupilID = PupilTrip.PupilID) AND (Trip.TripID = “14”)
ii) SELECT Teacher.Title, Teacher.Surname, Trip.Destination, Trip.StartDate
FROM Trip, Teacher
WHERE (Teacher.TeacherID = Trip.TeacherID) AND (Teacher.Surname = “Black”)
ORDER BY StartDate DESC
iii) SELECT Pupil.PupilFirstName, Pupil.PupilSurname, Teacher.FirstName, Teacher.Surname
FROM Pupil, PupilTrip, Trip, Teacher
WHERE (Pupil.PupilID = PupilTrip.PupilID) AND (PupilTrip.TripID = Trip.TripID) AND
(Trup.Destination = “Year 7”) AND (Trip.TeacherID = Teacher.TeacherID)
Harvey James

Chapter 65:
Q1: CREATE TABLE Student (
StudentID CHAR(6) NOT NULL, PRIMARY KEY,
Surname VARCHAR(20) NOT NULL,
FirstName VARCHAR(15) NOT NULL,
DateOfBrith DATE NOT NULL)
Q2: ALTER TABLE Student
ADD YearGroup INTEGER
Q3: CREATE TABLE Cource (
CourseID CHAR(6) NOT NULL, PRIMARY KEY ,
CourseTitle VARCHAR(30) NOT NULL,
OnSite BOOLEAN)
Q4: a) INSERT INTO Student
VALUES (AB1234, Daley, Jennifer, 23/06/2005)
b) UPDATE Student
SET FirstName = “Jane”
c) ALTER TABLE Student
ADD DateStarted Date
Q5: The address will be changed but not the credit limit as it was overwritten by user A
Exercises:
1. a) i) A table is in third normal form if it is in second normal form and contains no ‘non-key’
dependencies
ii) So that all attributes are dependent on the key
b)
Customer
Furniture
Order

Customer
Customer
OrderLine
Harvey James

c) CREATE TABLE Furniture (


FurnitureID CHAR(6) NOT NULL, PRIMARY KEY,
FurnitureName VARCHAR(30),
Category VARCHAR(30),
Price CURRENCY,
SupplierName VARCHAR(30))
d) SELECT Customer.CustomerName, Customer.TelephoneNumber
FROM Customer, CustomerOrder, CustomerOrderLine
WHERE (Customer.CustomerID = CustomerOrder.CustomerID) AND
(CustomerORder.OrderID = CustomerOrderLine.OrderID) AND
(CustomerOrderLine.FurnitureID = “10765”)
ORDER BY CustomerName ASC
2. a) When two or more people are changing a record at once only the last person to save
the record has their details implemented. This is because the last person overwrites all the
others before him/her.
b) Deadlock is when two or more users are attempting to update the same record and
neither can proceed
c) Time Stamp ordering can prevent this by preventing a transaction from starting until the
previous one has finished.

Chapter 66:
Q1: By linking the generation together to form a family tree to give structure to it.
Exercises:
1. a) This is where the stages of software development are not completed in a linear
sequence, with different parts being developed/tested at the same time. Prototypes are
built which are evaluated and improved until customer satisfaction.
b) This allows for improvements to be easily made and is more efficient as non-vital features
are not implemented which distracts time and energy.
2. a) How many courses will be used within the system, who are the primary users of the
system and how is the system is expected to grow?
b) Requirements are gathered, a prototype is built, the prototype is evaluated and refined,
this process repeats until the prototype satisfies the customer, the final system is then
created.

You might also like