20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

❑ You learned the importance of ensuring that data in a database remains valid — for example,<br />

ensuring that there are no duplicated values in primary key columns. The mechanism that disallows<br />

duplicate data is the constraint, which includes NOT NULL, UNIQUE, CHECK, PRIMARY KEY,<br />

and FOREIGN KEY.<br />

❑ You learned how to speed up query results by using indexes.<br />

❑ Using the chapter’s topics, you improved the Film Club database’s design, making it leaner,<br />

more efficient, and less likely to fall afoul of invalid data.<br />

The next chapter examines how to manipulate data returned by a query and covers such subjects as<br />

arithmetic in <strong>SQL</strong>.<br />

Exercises<br />

1. Your friend runs a bookstore and uses a simple database to store details of books, authors, and<br />

booksellers. She thinks the database might need a bit of a tune-up. Figure 4-2 shows its current<br />

structure, which consists of just one table containing two columns: Column Name and Data Type.<br />

Using what you learned about normalization, see if you can improve the current structure.<br />

Figure 4-2<br />

Advanced Database Design<br />

2. When improving the Film Club database, you added various constraints as well as primary and<br />

foreign keys. You didn’t, however, add a FOREIGN KEY constraint to the FavCategory table.<br />

Create and execute the <strong>SQL</strong> required to enforce all its relationships with the other tables.<br />

155

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

Saved successfully!

Ooh no, something went wrong!