next
Database Tables
What is a database table?
All database information is stored in "tables"
Any database table can be pictured as being in this format:
| Id | Bird Name | Age (days) | Sex | Parents |
| 001 | Peter | 320 | Male | Mary, Bob |
| 002 | John | 195 | Male | Mary |
| 4 | Mary | 770+/-5 | Female | Ellen |
| 005 | Jane | 30 | Female | Mary, John |
| 999 | Bob | 834 | Not Lately | Ellen |
| 6 | Ellen | 1001 | Female | NULL |
There are different types of tables you can use which have unique properties. For instance, some tables can be write locked during insertion or update of rows or read locked during any reading. Other table types allow a finer-grained approach by implementing row-level locking. More advanced tables and databases support things like the concept of a transaction (an all-or-nothing multi-step operation), automatic checking of primary and foreign key constraints, or cascading deletions.
Things to note:
- this is a badly designed table
- rows (almost) always represent a concept or a thing (in this case, a bird)
- we have given each row a unique id (to be used as a primary key)
- we have not really defined the column types - only strings? integer ids?
- age needs to be updated daily
- sex is not checked for implausible values
- the parent column can be blank
- a parent name is not required to exist in the table
- multiple parents break the tabular structure by creating ad-hoc extra columns
- it is not clear why this is better than a tab-separated column text file