25.09.2014 Views

ZEND PHP 5 Certification STUDY GUIDE

Create successful ePaper yourself

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

Database Programming ” 143<br />

primary keys differ from unique indices only in the fact that there can only be one of<br />

the former in each table, while an arbitrary number of the latter can exist.<br />

Relationships<br />

As we mentioned at the beginning of this chapter, data relationships are one of the<br />

most important aspects of relational databases. Relationships are established between<br />

tables so that the consistency of data is ensured at all times; for example, if<br />

your database contains a table that holds the names of your customers and another<br />

table that contains their addresses, you don’t want to be able to delete rows from the<br />

former if there are still corresponding rows in the latter.<br />

Relationships between tables can be of three types:<br />

• One-to-one—at most, one row in the child table can correspond to each row in<br />

the parent table<br />

• One-to-many—an arbitrary number of rows in the child table can correspond<br />

to any one row in the parent table<br />

• Many-to-many-an arbitrary number of rows in the child table can correspond<br />

to an arbitrary number of rows in the parent table<br />

It’s interesting to note that the SQL language only offers the facilities for directly creating<br />

one-to-one and one-to-many relationships. Many-to-many relationships require<br />

a bit of trickery and the use of an “intermediate table” to hold the relationships<br />

between the parent and child tables.<br />

SQL Data Types<br />

As we mentioned above, SQL is the most common database manipulation language<br />

(DML) used in relational databases, and SQL-92, as defined by the American National<br />

Standards Institute (ANSI), is its most commonly-used variant. Although SQL<br />

is considered a “standard” language, it is somewhat limited in relation to the realworld<br />

needs of almost any application. As a result, practically every database system<br />

in existence implements its own “dialect” of SQL, while, for the most part, maintaining<br />

full compatibility with SQL-92. This makes writing truly portable applications<br />

very challenging.<br />

Licensed to 482634 - Amber Barrow (itsadmin@deakin.edu.au)

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

Saved successfully!

Ooh no, something went wrong!