Understanding Databases
The topic of database theory is deep and entire books have been written on the subject. Serious application developers need to master a lot of database theory before they can create sophisticated applications. But, as with most technical subjects, you can get a lot done with only a basic understanding of the technology at hand. One goal in these lessons is to give you some experience working with databases, DSNs, and dynamic pages, so you can build common applications and are primed to take on more advanced books or training if you wish.Databases are made up of a series of tables. A database table is a collection of rows and columns, and looks very much like an Excel spreadsheet. What makes database tables special is that they can link to one another. For example, imagine a small business that sells pet products online. This business's database might include three tables, as follows:Customers: This table is for a list of all the company's customers: first name, last name, street address, city, state or province, postal code, country, phone number, and so on.Inventory: This table contains a listing of all the company's products, including the name, quantity on hand, price, location, and so forth.Transactions: This table contains a listing of all the sales through the Web site. It includes the date of the transaction, total price of the transaction, name and quantity of the items sold, and the name of the customer to whom they were sold.The magic of this setup is that the Transactions table links to the Customers and Inventory tables. Thus, for transaction number 247, rather than listing Jane Smith, 112 Cheshire Lane, Toronto, Ontario, Canada, her phone number, and all her other particulars, the table simply lists a unique ID number associated with her, and pulls up the rest of the information as needed, on the fly. Likewise, for inventory, if Jane orders six bags of catnip, the inventory amount is automatically deducted. Each piece of information needs to be maintained in only one place, and is referenced as needed by other tables.In the remaining lessons, you will not take advantage of the relational potential of databases (we're assuming that you do not have Microsoft Access). Even so, it's important to understand what tables are, that one database can have multiple tables, and that you can establish relationships between tables.The following figure shows the users table of the database used in this lesson. Notice that every row (technically called a record) contains an instance of every column (database columns are called fields). Although each record canand usually doeshave different information in each field, they all share the same fields; only the values in them change.[View full size image]
