The Basics of Databases

Simple Database

The simplest kind of database is a flat file, consisting of information about a single entity.




Entities

An entity is a category of object, person, event or thing of interest about which data needs to

be recorded. Eamples of entities would be: Customer, Product or Subscription (for a digital textbook service).




Records

In a database, a record is a group of fields within a table that are belong to a specific entity.

The different fields in a record for the digital textbook example could be:

  • Customer (custID, title, firstname, surname, email)
  • Product (productID, title, subject, level, price)
  • Subscription (subID, startDate, endDate)

Primary Key


Each entity needs an identifier which uniquely identifies a particular record. This is called a Primary Key. 

Each Primary key is totally unique for every record.



Composite Primary Key

Sometimes multiple unique IDs are required to identify a record (if there was a order number and product number for example). These are called Composite primary keys. 

When writing Primary Keys in an exam situation you identify them by underlining them.



Secondary Key

Secondary keys are a second way of searching a database. They are not unique to a record but will narrow down results. For example a book author's name good be searched in a library database. 





Entity Relationships

Entities are usually linked in some way. This is represented using diagrams. 



We can say, for example, that one school has many pupils, or many pupils attend one school.



A customer can have multiple subscriptions (many subscriptions), of which each subscription is linked to one product. 



Foreign Key

A foreign key is an attribute that creates a join between two tables (relations). 



Referential Integrity

This means that no foreign key in one table can reference a non-existent record in another. 

For example: it should not be possible to add a subscription for a customer with custID C100 if there
is no record for customer C100. 



Relational Databases


Data is held in separate tables are linked by common attributes.

A row on a table is called a record.

The columns in the tables represent different attributes.



Indexing

Database software automatically keeps a record of all Primary keys. This allows for records to easily be searched for.

Sometimes other terms can be used to search the table. Such as secondary keys (book author for example). This will speed up and make searching easier.


Normalisation

Normalisation is used to come up with the best possible design for a database.

This means data is not duplicated, data is consistent throughout the database and the structure should be flexible to allow the user to carry out complex queries. 

Comments

Popular posts from this blog

CPU Fetch-Decode-Execute Cycle

Scheduling

Utility Software