20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Appendix A<br />

ZipCode,<br />

Email,<br />

DateOfJoining<br />

)<br />

VALUES<br />

(<br />

9,<br />

‘Seymour’,<br />

‘Botts’,<br />

‘21 Oct 1956’,<br />

‘Long Lane’,<br />

‘Windy Village’,<br />

‘Golden State’,<br />

‘65422’,<br />

‘Seymour@botts.org’,<br />

‘17 July 2005’<br />

);<br />

Exercise 2 Solution<br />

First, remove Bob Robson’s details from the database. His member details are stored in the<br />

MemberDetails table, and his favorite film categories are in the FavCategory table. Each record in the<br />

FavCategory table contains only the MemberId and the CategoryId. Remember from Chapter 1 that the<br />

MemberId field in this table is a foreign key; its value is referenced from the MemberDetails table, where<br />

it’s a primary key. Therefore, you must delete the records from the FavCategory and Attendance tables<br />

first:<br />

DELETE FROM FavCategory WHERE MemberId = 2;<br />

DELETE FROM Attendance WHERE MemberId = 2;<br />

Once you delete Bob from the FavCategory table, you can delete him from the MemberDetails table:<br />

DELETE FROM MemberDetails WHERE MemberId = 2;<br />

Exercise 3 Solution<br />

372<br />

Update the database to reflect the Orange Town boundary changes. You need to change the City field<br />

from Orange Town to Big City where the street is Long Lane and the city is Orange Town.<br />

Remember that there is also a Long Lane in Windy Village, so you can’t just check the street name. You<br />

need to update only if the street is in Orange Town:<br />

UPDATE MemberDetails SET City = ‘Big City’<br />

WHERE Street = ‘Long Lane’ AND City = ‘Orange Town’;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!