8 - Databases
8 - Databases
Databases:
It is a collection of data which is stored in an organized way.
Relation Database:
Database in which data items are linked to each other by pointers.
Benefits of a database approach:
Items are stored once so storage space isn’t wasted.
Data is consistent as when it is altered in one application it is also edited in the other.
Data is independent as the enquires are not dependent on the structure of data.
Entity:
Something about which data is stored.
Table:
It is a group of similar data consisting of rows and columns. The rows store instances of the entities while
the columns store the attributes.
Record:
It is a row in a table.
Field:
It is a column in a table.
Tuple:
It is the instance of an entity which is stored in a row in a table.
Attribute:
An individual data item stored for an entity.
Primary key:
it is used to uniquely identify a record in a table. For example, the student roll number is a primary key in
a table of STUDENTS.
Composite key:
When 2 or more attributes are used as a primary key. For example, in an attendance relation, the date,
time and registration# will serve as the composite key.
Foreign key:
It is a reference to the primary key of another table. Its purpose is to create a relation between 2 tables.
For example, in a fee relation, the registration number will be the foreign key.
1
Databases
Secondary/ Alternate key:
It is used to access data in a relation without the primary key. Indexing is the setting up of secondary
keys.
Candidate key:
It is used to serve as a primary key. It is unique to each element. All attributes are primary keys.
However, most tables have candidate keys which serve as the primary key.
Types of Databases:
Flat File
The files are interlinked with each other which reduces the repetition of data. This results in less
size of the database.
Data is consistent as when changes are made to one file, all the instances of the data are updated.
When validation constraints are modified, it is applied across the whole database. Therefore, it
has high data integrity.
Complex queries can be easily written to find specific data.
Different users can be given different access/ viewership rights which maintains the privacy and
security of the data.
Relationships in databases:
2
Databases
A relationship in a database is formed when one table has a foreign key which refers to the primary key of
another table in the same database.
Take these 2 tables as an example. In the table STUDENT, the Class ID field is the foreign key which
refers to the Class ID field in the CLASS table, which is a primary key.
STUDENT table
CLASS table
3
Databases
Dependency:
It occurs in a database when information in the table and an attribute uniquely determines other
information in the table. For example, Attribute A is dependent on attribute B.
Types of Dependency:
1. Full Dependency
When one or more primary keys determine another attribute.
STUDENT (Roll#, Surname, Subject)
2. Partial Dependency
When the key is composite but not all of the columns of the key determine another
attribute.
COURSE(Coursecode, Roll#, Coursename, Studentname)
3. Transitive Dependency
When non- key attribute determines another attribute.
COUNTRY(Code, City, Countryname, Population)
Normalization:
It is used to remove the redundancy of data. It uses full dependency only.
Types of Normalization:
1. First Normal Form (1NF)
All fields/ attributes must have a single value.
Remove all repeating groups.
All tables/ relations must have a primary key.
2. Second Normal Form (2NF)
Database must be in 1NF.
Every non- key attribute must be fully dependent on the primary key.
Remove the partial dependencies.
Non key attributes must be partially dependent on the primary key.
Remove transitive dependencies.
3. Third Normal Form (3NF)
Database must be in 2NF.
4
Databases
All non- key attributes must be fully dependent on the primary key.
Remove partial dependency.
Database Management System (DBMS)
Data Redundancy:
Refers to the presence of the same data within the same table.
Solution to Data Redundancy:
Data items will be stored once which will help improve data integrity.
Data Dependency issue:
Stores the definition of tables, attributes and relationship between tables in a database.
Also allows to define the validation rules.
Improves the integrity of the data stored.
Data Modelling:
5
Databases
It processes and executes the instructions written in SQL.
Includes the DDL interpreter and DML compiler.
These are then recorded in the database data dictionary.
Name and describe 2 levels of the schema of a database.
External:
How the individuals view the data.
Physical:
How data is stored on media.88
DDL (Creation) Commands
6
Databases
7
Databases
WHERE Product_ID= PI1
Past Papers:
Tasks that can be performed using DBMS developer interface. [3]
Create table.
Create relations.
Create forms, reports and queries.
Reasons why a database is fully normalized:
It has no repeating groups (1NF).
It has no partial dependencies. (2NF).
It has no transitive dependencies. (3NF).
Example of Insert Into:
INSERT INTO SHOP-SUPPLIER
(ShopID, SupplierID)
VALUES (8765, ‘SUP89’);
What is meant by referential integrity? [3]
Makes sure that the unexisting data doesn’t get referenced.
Primary keys can’t be deleted without the deletion of all dependent records.
Primary keys can’t be updated without the updating of all dependent records.