Beginning SQL

Beginning SQL Beginning SQL

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

The FilmCategory table is very small and simple. The SQL you need to create it is likewise very simple: CREATE TABLE Category ( CategoryId integer, Category varchar(100) ); The final table you need to create is called FavCategory, and it stores each member’s favorite film categories: Field Name Data Type Notes CategoryId integer Foreign key MemberId integer Foreign key As you can see, it’s a very simple table! Both CategoryId and MemberId are foreign keys, the first from the Category table and the second from the MemberDetails table. Combined, they make up a unique primary key. The SQL to create the FavCategory table is as follows: CREATE TABLE FavCategory ( CategoryId integer, MemberId integer ); Creating the FavCategory table completes the basic database structure. As you can see, creating a database is actually fairly easy! Chapter 4 covers more complex examples and options, but what you learned in this chapter lays a good foundation of database creation. Summary This chapter walked you through the fundamentals of SQL and database design and provided you with instruction on how to write the SQL code necessary to create a database’s structure. You now have enough knowledge to start designing your own databases. In this chapter, you discovered the following: Introduction to SQL ❑ Databases are an efficient way to store large amounts of raw data. They don’t process the data; that’s left to the application that uses the data. ❑ Databases make sharing data easier than do other means, such as text files, spreadsheets, or other documents. They also allow secure data sharing and allow you to define the levels of user access. You can limit what you let others do to your database’s data. ❑ Relational databases contain tables and fields and provide ways of relating data in different tables and ways of ensuring that any data entered is valid and doesn’t corrupt the database. 39

The FilmCategory table is very small and simple. The <strong>SQL</strong> you need to create it is likewise very simple:<br />

CREATE TABLE Category<br />

(<br />

CategoryId integer,<br />

Category varchar(100)<br />

);<br />

The final table you need to create is called FavCategory, and it stores each member’s favorite film<br />

categories:<br />

Field Name Data Type Notes<br />

CategoryId integer Foreign key<br />

MemberId integer Foreign key<br />

As you can see, it’s a very simple table! Both CategoryId and MemberId are foreign keys, the first from<br />

the Category table and the second from the MemberDetails table. Combined, they make up a unique primary<br />

key. The <strong>SQL</strong> to create the FavCategory table is as follows:<br />

CREATE TABLE FavCategory<br />

(<br />

CategoryId integer,<br />

MemberId integer<br />

);<br />

Creating the FavCategory table completes the basic database structure. As you can see, creating a<br />

database is actually fairly easy! Chapter 4 covers more complex examples and options, but what you<br />

learned in this chapter lays a good foundation of database creation.<br />

Summary<br />

This chapter walked you through the fundamentals of <strong>SQL</strong> and database design and provided you with<br />

instruction on how to write the <strong>SQL</strong> code necessary to create a database’s structure. You now have<br />

enough knowledge to start designing your own databases.<br />

In this chapter, you discovered the following:<br />

Introduction to <strong>SQL</strong><br />

❑ Databases are an efficient way to store large amounts of raw data. They don’t process the data;<br />

that’s left to the application that uses the data.<br />

❑ Databases make sharing data easier than do other means, such as text files, spreadsheets, or<br />

other documents. They also allow secure data sharing and allow you to define the levels of user<br />

access. You can limit what you let others do to your database’s data.<br />

❑ Relational databases contain tables and fields and provide ways of relating data in different<br />

tables and ways of ensuring that any data entered is valid and doesn’t corrupt the database.<br />

39

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

Saved successfully!

Ooh no, something went wrong!