Beginning SQL

Beginning SQL Beginning SQL

marjan.fesb.hr
from marjan.fesb.hr More from this publisher
20.07.2013 Views

The index is no longer needed, so delete it with the following code. If using MS SQL Server, write the following DROP INDEX statement: DROP INDEX MemberDetails.member_name_indx; In IBM DB2 and Oracle, the DROP INDEX statement simply requires the index name without the table name prefixed: DROP INDEX member_name_indx; In MySQL, the code to drop the index is as follows: ALTER TABLE MemberDetails DROP INDEX member_name_indx; MS Access has yet another way of dropping the index: DROP INDEX member_name_indx ON MemberDetails; You’ve learned a lot of useful stuff for improving the design and efficiency of your databases. The next section takes that knowledge and applies it to the Film Club database. Improving the Design of the Film Club Database This section revisits the Film Club database, taking into account the topics discussed in this chapter: normalization, ensuring data integrity with constraints, and using indexes to speed up data retrieval. The discussion begins with an examination of the database structure and then turns to constraints and indexes. Reexamining the Film Club Database Structure Generally speaking, the database is in third normal form, with the exception of the MemberDetails table. The Street, City, and State columns are all transitively dependent on the ZipCode column. Therefore, the MemberDetails table is still in second normal form. The question now, however, is one of common sense, because the amount of duplication reduced by going to third normal form is going to be quite small. It’s unlikely that many people from the same street would join the club, and with a small database, storage size is not usually an issue. In addition, changing the table to comply with third normal form involves creating another table, and as a result any SELECT queries require another JOIN statement, which impinges on database efficiency. Therefore, in this instance, the database is fine as it is, and moving the MemberDetails table to third normal form is probably unnecessary and only adds complexity without really saving any storage space. However, one area of the database design needs altering: the Attendance table. Consider the following query: SELECT * FROM Attendance; Advanced Database Design 143

The index is no longer needed, so delete it with the following code. If using MS <strong>SQL</strong> Server, write the<br />

following DROP INDEX statement:<br />

DROP INDEX MemberDetails.member_name_indx;<br />

In IBM DB2 and Oracle, the DROP INDEX statement simply requires the index name without the table<br />

name prefixed:<br />

DROP INDEX member_name_indx;<br />

In My<strong>SQL</strong>, the code to drop the index is as follows:<br />

ALTER TABLE MemberDetails<br />

DROP INDEX member_name_indx;<br />

MS Access has yet another way of dropping the index:<br />

DROP INDEX member_name_indx ON MemberDetails;<br />

You’ve learned a lot of useful stuff for improving the design and efficiency of your databases. The next<br />

section takes that knowledge and applies it to the Film Club database.<br />

Improving the Design of the Film Club Database<br />

This section revisits the Film Club database, taking into account the topics discussed in this chapter: normalization,<br />

ensuring data integrity with constraints, and using indexes to speed up data retrieval.<br />

The discussion begins with an examination of the database structure and then turns to constraints and<br />

indexes.<br />

Reexamining the Film Club Database Structure<br />

Generally speaking, the database is in third normal form, with the exception of the MemberDetails table.<br />

The Street, City, and State columns are all transitively dependent on the ZipCode column. Therefore, the<br />

MemberDetails table is still in second normal form. The question now, however, is one of common sense,<br />

because the amount of duplication reduced by going to third normal form is going to be quite small. It’s<br />

unlikely that many people from the same street would join the club, and with a small database, storage<br />

size is not usually an issue. In addition, changing the table to comply with third normal form involves<br />

creating another table, and as a result any SELECT queries require another JOIN statement, which<br />

impinges on database efficiency. Therefore, in this instance, the database is fine as it is, and moving the<br />

MemberDetails table to third normal form is probably unnecessary and only adds complexity without<br />

really saving any storage space.<br />

However, one area of the database design needs altering: the Attendance table. Consider the following<br />

query:<br />

SELECT * FROM Attendance;<br />

Advanced Database Design<br />

143

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

Saved successfully!

Ooh no, something went wrong!