Database

From Wikipedia, the free encyclopedia

Jump to: navigation, search

A Database is a program for a computer. It is used to manage data. A very simple example of a database would be an electronic address book.

The data in a database is organised in some way. Before there were computers, employee data was often kept in file cabinets. There was usually one card for each employee. On the card, information such as the date of birth or the name of the employee could be found. A database also has such "cards". To the user, the card will look the same as it did in old times, only this time it will be on the screen. To the computer, the information on the card can be stored in different ways. Each of these ways is known as a database model. The most commonly used database model is called relational database model; it used relations and sets to store the data. Normal users talking about the database model will not talk about relations, they will talk about database tables.

Contents

[change] Things database systems usually do

There are certain things database systems usually do:

  • They store the data
  • They store special information used to manage the data. This information is called metadata.
  • They can solve cases where many users want to access (and possibly change) the same entries of data.
  • They manage access rights (who is allowed to see the data, who can change it)
  • When there are many users asking questions to the database, they make these questions better (so that they can get a result faster)
  • Certain attributes are more important than others, they can be used to find other data. This is called indexing. An index contains all the important data and can be used to find the other data.
  • They ensure that the data always makes sense. There are certain rules that can be added to tell the database system if the data makes sense. One of the rules might say November has 30 days. This means if someone wants to enter November 31 as a date, this change will be rejected.

[change] Changing data

In databases, some data changes occasionally. There may be problems when data is changed, an error might have occcurred. The error might make the data useless. The database system looks that the data always makes sense. It does this by using something called a transaction. There are two points in time in the database, the time before the data was changed, and the time after the data was changed. If something goes wrong when changing the data, the database system simply put the database back into the state before the change happened. This is called rollback. After all the changes could be done successfully, they are committed. This means that the data makes sense again; committed changes can no longer be undone

In order to be able to do this, databases follow the ACID principle:

  • All. Either all tasks of a given set (called transaction) are done, or none of them is. Known as Atomicity
  • Complete. The data in the database always makes sense. There is no half-done (invalid) data. Known as Consistency
  • Isolation. If many people work on the same data, they will not see (or impact) each other. Each of them has their own view of the database, which is independent of the others
  • Done. Transactions must be committed, when they are done. Once the commit has been done, they can no longer be undone. Known as Durability.

[change] Database model

There are different ways how to represent the data.

  • Simple files (called flat files): Simply write the data into a number of big files.
  • Hierarchical model: The data is organised like a tree structure. The interesting data is at the leaves of the tree
  • Network model: Use records and sets to store the data
  • Relational model: This uses set theory and predicate logic. It is very widely used. Data looks like it is organised in tables. These tables can then be joined together so that simple fields can be chosen from them.
  • Object relational model: This uses the same data types for the database, as for the (object-oriented) application.

[change] Ways to organise the data

Like in real life, the same data can be looked at from different perspectives, and it can be organised in different ways. There are different things to consider, when organising the data:

  • Each item of data should be stored as few times as possible. Imagine that an unmarried woman wrote a book. Once she marries, her name will change. If her name is only stored once, updating is easy, if it is stored several times it becomes harder. Also, if the data is stored several times, it may contradict itself.
  • There is a lot of data., that will take up a lot of space. If things are repeated over and over again, even more space will be taken. This will make finding things slower.

Based on these criteria, a method called Database normalisation was developed. Currently there are 5 Normal forms. These are a way to make a database faster, and make the data take less space.