1/86
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Foreign key
A foreign key is a primary key in one table which is sued as an attribute in another table to provide a link between table.
A foreign key in one table is always linked to a key field in another table.
Compound key
A combination of fields that makes a record unique (but breaks 2 Normal Form)
Normalisation
The process of refining the structure of a database to minimise redundancy and improve integrity
When a database has been normalised, it is said to be in normal form
Helps organise the data efficiency, eliminate redundant data, ensure that only related data are stored in a table
1NF - First Normal Form
A table is in this form if it contains no repeating attributes or groups of attributes, data is atomic, AND has a primary key
RDBMS
Relational Database Management System
Used to maintain data integrity
Uses SQL which allows you to crate, delete, and alter the database
Has a way of documenting all the internal structures that make up the database
The ability to view the database from different viewpoints according to the requirements of the user
Provide some level of security and access control to the data
Data Definition Language (DDL)
Helps to provide a method of creating a database from scratch
Used to write schema (designs) which describes data items to be stored and the relationships between them.
Allows tables to be created and primary/foreign keys to be defined.
Also defines validation rules
What is exchanging data?
The process of transferring the collected data to a database
Things to know about SQL commands
SQL commands are in capital letters
Multiple fields are separated by commas
Alter and drop are to do with structure
Update and delete from are to do with data
How do you add in a new field?
ALTER TABLE tablename ADD columnname datatype
How do you remove an existing field?
ALTER TABLE tablename DROP COLUMN columnname
How do you create a table within a database? (e.g Clubs)
CREATE TABLE Clubs ( ClubID INT NOT NULL, ClubName VARCHAR(50) NOT NULL, PRIMARY KEY (ClubID))
How do you insert data into a database?
INSERT INTO databasename.tablename (field1, field2) VALUES ('1', 'The Pullman Club');
How do you change a record?
UPDATE databasename.tablename Fieldname = ‘data’ WHERE tablename.primarykeyname = “primarykey”
How do you extract a sub-set of the table records?
SELECT * FROM tablename WHERE primarykey>1
How do you return a single record?
SELECT * FROM tablename WHERE primarykey=2
How do you include more than one table in the search?
SELECT fieldname(s) FROM table1
JOIN table2
ON table1.primarykey = table2.foreignkey
How do you delete records?
DELETE FROM tablename WHERE primarykey = 1
Methods of exchanging data
Data can be transferred:
Automatically using the DBMS software
By typing it in using a customised form
Importing it from another type of file
Using EDI (Electronic Data Interchange) this is used to transfer data between one computer system and another
APIs (application programming interfaces) uses web services to communicate using the HTTP protocol
SOAP a standardised protocl that sends messages using HTTP and SMTP
JSON (JavaScript Object Notation)
XML (Extensible Markup Language) used to separate data from its presentation on web pages
No matter which method is used, validation should occur to ensure that the data is sensible along with verification to ensure that the data entered matches the original
Transaction Processing
A single logical operation on data (e.g a customer booking a cinema ticket online, even though it involves multiple actions)
The database must ensure that it is not possible to only complete part of a transaction.
e.g. if seats have been successfully reserved, but payment fails, the seats should not stay reserved or change status to booked.
ACID (Atomicity, Consistency, Isolation, Durability) is a set of properties that guarantee that transactions are processed reliably.
Atomicity
Ensures that a transaction must be processed in its entirety or not at all
It must guarantee that in any situation, including power cuts or hard disk failure, it is not possible to only process part of a transaction.
Transactions should either succeed or fail but never partially succeed.
Consistency
The transaction should only change the database according to the rules of the database in order to maintain its integrity
Changes to data in one table must take into account data in linked tables
This means that it will not be possible to create or delete a record if related records exist in linked tables e.g.
an employee cannot be deleted if they have salary details in another table
you can’t create a salary for an employee that doesn’t exist
Isolation
This property ensures that concurrent execution of transactions leads to the same results as if the transactions were processed one after the other.
i.e. Each transaction should not overwrite other transactions that are being processed at the same time
This is particularly relevant in a multi-user database where each transaction must not affect/overwrite other transactions being processed at the same time
Durability
Ensures that once a transaction has been committed, it will remain so, even in the result of a power cut.
e.g. in an online cinema ticket purchase, it should not be possible for the number of seats sold to be updated if the credit card transaction fails
As each part of the transaction is completed, it is held in a buffer on disk until all elements of the transaction have been completed.
Only then will the changes to the database be made.
Multi-user Database
These need to allow for concurrent processing
If multiple users need to read the same data, it generally isn't a problem, but allowing multiple users to simultaneously update or write to a database table may cause one of the updates to be lost unless measures are taken to prevent it.
When an item is updated, the entire record will be copied into the user’s own local memory (on their local device).
When the record is saved, the data in memory is then rewritten in its entirety.
This can lead to unexpected results
Record locking
In its simplest form, the record is “locked” when the first user obtains the data and cannot be accessed by any other user until it is “unlocked” (saved).
However, this can cause problems…
If two users try to access a single record at the same time a situation can arise where neither can proceed, known as deadlock.
The DBMS (Database Management System) must recognise if this happens and must deal with the deadlock.
Serialisation
When two or more transactions are executed concurrently, the effect should be the same as if they had been executed serially i.e. one after the other.
It ensures that transactions do not overlap in time and therefore cannot interfere with each other or lead to updates being lost.
A transaction cannot start until the previous one has finished and this can be implemented using:
Timestamp ordering
Commitment ordering
Timestamp Ordering
Whenever a transaction starts, it is given a timestamp, so that it two transactions affect the same object, the transaction with the earliest timestamp should be applied first.
Each transaction is given a read timestamp and a write timestamp.
When a transaction starts, it reads a record of data, causing it to be read timestamped.
When the updated data is written back, the read timestamp is checked.
If it is not the same in the database as the current record in memory steps are taken to solve the problem
Commitment Ordering
Transactions are ordered in terms of their dependencies on one another as well as the time they were initiated.
This involves evaluating the impact of the transactions before they are executed i.e. which data will be updated and how that will potentially affect other transactions
It can be used to prevent deadlock by blocking one request until another is completed.
Transactions are not completed in time order, but in commitment order
Redundancy
This could be a RAID(Redundant Array of Inexpensive Disks) setup or mirroring servers.
In its simplest(!) form, these organisations maintain two or three identical systems in different geographical locations, so that every transaction is written to two or three storage facilities.
This hardware redundancy protects against the loss of data in the event of power failure or other disasters.
If one system fails, one of the backup systems automatically takes over and processing continues.
If part of a database is lost, it can be recovered from one of the other versions.