RDBMS Definition
Relational databases store data in tables (relations) that are two dimensional. The tables have rows (records or objects) and columns (fields or attributes). Data items at an intersection of a row and a column are called a cell and consist of attribute values. Data stored is simple data such as integers, real numbers or string values. Multiple values may not be stored in one cell. Relational database tables are "normalized" so data is not repeated more often than necessary. All table columns depend on a primary key (a unique value in the column) to identify the column. Once the specific column is identified, data from one or more rows associated with that column may be obtained or changed.
Relational databases are sets of tables. One table file is not a relational database. A relational database server is not the same as a relational database. A relational database can be a file with sets of tables. The relational database server includes the ability to service requestesto get or change data from remote clients.
Relational database servers use Structured Query Language (SQL), as a data manipulation language to interface between itself and the clients. SQL is the standard for getting and storing data in an RDBMS. For information about SQL, see the "Beginner's SQL Guide".
Relational database servers provide:
- Data Management
- Transaction processing
- Data integrity - Provides for multiple access at the same time (concurrency) between multiple processes/users. This is done so data is not displayed nor saved in a fashion where one change is lost. Various locking mechanisms are used to support this.
- Data backup and recovery.
- Data security - Provides for user authentication, and levels of data access privileges.
Primary Keys
In relational databases, the data is not arranged in any particular order in tables. The data in tables requires keys for identification of rows. Each table has rows and columns. Sets of values in a row may describe a particular item such as customers. Consider the following table:
Customers
Customer ID | Name | Street Address | City | Zip Code | Phone | e-mail |
112304 | John Brown | 123 Straight Lane | Paradise | MI | 49555 | johnb@heaven.net |
134056 | Tim Smith | 321 Curved Ave | Hollywood | MD | 10255 | tims@eastnet.net |
234902 | Sue Jones | 213 Hill Road | Knoxville | TN | 23555 | suej@nicenet.net |
092387 | George Abernathy | 555 North Road | Smalltown | FL | 67555 | georgea@mynet.net |
187462 | Tom Jenkins | 666 South Lane | Cold | MN | 55555 | tomj@networks.com |
108976 | Kim Adams | 456 Peachtree Lane | Atlanta | GA | 54555 | kima@bestnet.net |
059385 | Chris Christopher | 859 East Road | Nicetown | MS | 45555 | chrisc@bignet.com |
140763 | Jim Thompson | 307 West Ave | Bigcity | ND | 65555 | jimt@fastnet.net |
Columns include Customer ID, Name, Street Address, City and so forth. Each column has a different set of information about all customers such as their phone number. This information could be considered customer characteristics or attributes. Each row has all information about one particular customer. Each row must have a unique means of identification. We could have used the customer name to identify the customer, but it is possible that more than one customer may have the same name. Therefore we are using unique customer identifiers. The Customer ID is the key used to identify individual customers. The column to be used as the key must be identified to the relational database. This is called the primary key.
Foreign Keys
Let's say we're running a store with the customers listed above. The first table below lists items for sale. The second table lists orders that have been placed in the store, and the third table lists items ordered for an individual order. If we want to print out what items customer 234902 ordered we do the following:
- Go to the orders table and get all orders customer 234902 ordered.
- For each order found (1 order #190389575). The order number is considered to be a foreign key to another table and column which is to table "Individual Order 190389575" and Item ID.
- Go to the "Individual Order 190389575" table and get each item ID that was ordered. Each item ID is a foreign key to the "Store Items" table and Item ID column.
- Go to the store items table, find each item ID and print out each item attribute such as price, description, and quantity purchased (from the individual order table).
Store Items
Item ID | Description | Price |
000234567 | Small Flower Pot | 2.36 |
000018901 | Potting Soil | 5.97 |
001034654 | Geranium Seed | 1.50 |
Orders
Order ID | Customer ID | Subtotal | Tax | Total |
190389575 | 234902 | 16.16 | 0.82 | 16.98 |
109748230 | 187462 | 2.37 | 0.12 | 2.49 |
208949023 | 059385 | 104.23 | 5.22 | 109.45 |
103792034 | 187462 | 40.00 | 2.00 | 42.00 |
123048938 | 134056 | 10.00 | 0.50 | 10.50 |
Individual Order 190389575
Item ID | Quantity |
000234567 | 2 |
000018901 | 2 |
001034654 | 1 |
Therefore foreign keys are used to access data in related tables.
No comments:
Post a Comment