|
|
|
|
Relational databases implement the Relational Model formulated by E.F. Codd in his seminal paper "A Relational Model of Data for Large Shared Data Banks", Communications of the ACM, 1970. The Relational ModelThe major features of the Relational Model are:
Relational TerminologyHere is some terminology commonly used in relational databases:
For example, imagine a database which stores information about employees for a company. An Employees table might look like the following:
and a Departments table might look like:
Note that, in the above example, there are two columns which refer to rows in the other table:
This is done in the relational model to avoid duplication of data, and to improve the data structure/organization. Relational Data TypesEach column in a relational database table has a data type. The Relational Model emphasizes that each column's data type must be atomic; that is, a data type is indivisible and must be treated as a unit. Some common datatypes are:
Most relational databases today provide more complex types such as Binary Large Objects (BLOBs) and Character Large Objects (CLOBs), which may in fact be considered divisble by the user (although perhaps not by the database itself). The value of a particular data type can:
Relational OperationsThe Relational Model defines a number of operations that may be performed on tables, on rows, and on individual data elements. SelectionThe most important operation is selection. This is the operation of selecting one or more rows from a table which satisfy one or more predicates. A predicate is a statement about the truth of something (for example, whether the employee ID is equal to 1234, or whether his/her salary is higher than $20000.) The rows in the table are filtered on the basis of whether they satisfy the predicate(s). JoinA common relational operation is that of a join. A join involves one or more tables, and involves combining rows and columns from those tables into a new set of data which also forms a (temporary) table with a new set of columns and rows. For example, if you wished to list all the departments and their managers in the above employees example, you would have to perform a combination of a join operation and a selection operation to come up with a table that looks something like:
UnionIt sometimes happens that two or more tables have the same structure of columns and data types. If you wished to produce a report that combined the data from the two tables, you would perform a union operation to accomplish this. For example, you might have a Customers table which could contain similar information to the Employees table (except of course for the Employee ID and Department columns). You could use a combination of selection, join and union to come up with a table that contains rows of data from both the Employees and the Customers tables. ClosureA very important aspect of the relational model is the concept of closure, which says that the result of any operation on one or more relations is also a relation. The Transaction ModelMost relational databases support the concept of a transaction. A transaction is a unit of work performed against a database which must either completely succeed or completely not succeed. For example, imagine that you work for a bank, and you wish to transfer money from one account to another account. To accomplish this, you would have to perform the following steps in the following sequence:
But what if something went wrong after step 1) that prevented you from completing step 2)? Without the concept of a transaction, you would likely lose track of the money withdrawn, and the banks books would no longer balance. If you perform the two steps within a transaction, the database takes care to ensure that one of the following occurs:
or:
Commit vs RollbackWhen a transaction is ready to complete all its operations, it asks the system to commit those actions. When a transaction discovers difficulty with performing its actions, and decides that all those actions cannot be performed, then it asks the system to rollback any actions that it has (provisionally) performed. The ACID PropertiesIt is generally agreed that a database transaction must have the following "ACID" properties:
|
| The page was last updated February 19, 2008 |