Databases Flashcards
Characteristics of a database
Data is logically related (entities with attributes and relations to other entities)
Self-describing (schema/metadata)
Data abstraction (separation of internal and external representation)
3-level way of representing a database management system
External level: the user’s view
Internal level: The technical part
Conceptual level: How the two interact
Advantages and disadvantages of using a DBMS
Advantages: control over data redundancy, consistency, standards, improved accessibility, improved accessibility and productivity (can extract more information from the same amount of data), improved maintenance, scaling
Disadvantages: complexity, size, performance (sometimes worse than single-purpose systems), single point of failure
How does the relational data model work
A relation is a table with rows and columns
A column is called an attribute (or field)
A row is called a record
Two tables are often related by a third table (e.g. Students and Courses are related by a StudentCourses table)
What is Entity-Relationship Modelling?
A way of communicating databases graphically: non-technical, free of ambiguities
Examples include crow’s feet notation and UML
Specifies attributes, relationships, constraints
What is normalisation?
The process of reducing data redundancy and minimising the number of attributes across all tables. This helps avoid update anomalies and saves space.
Creating a table with SQL
CREATE TABLE Staff (staffNo VARCHAR(5), LName VARCHAR(15), salary DECIMAL(7,2));
Inserting records into a table with SQL
INSERT INTO Staff VALUES (“SG16”, “Brown”, 8300);
Querying a table with SQL
SELECT staffNo, LName, Salary
FROM Staff
WHERE salary > 10000;
Purpose of three-level architecture
Realises data abstraction: Users can access same data but have different customised views
Users can change views without affecting other users
Internal structure can be changed without affecting users
External level
Users’ view of the database
Multiple different views of the same data (e.g. 20 Jan ‘22 vs 2022-01-20)
Adapted to specific needs
Different entities, attributes, relationships
Possibly derived/calculated/combined (e.g. getting age from date of birth)
Conceptual level
Community view of the database, shared by all users
Describes what data is stored (entities, attributes, relationships, constraints, security/integrity information)
Internal level
Physical representation of the DB
Describes how the data is stored to achieve optimal runtime performance and storage utilisation
Interface to operating system
Compression and encryption
DB schema
The description of the database, the result of the design process
Should not change
Multiple external subschemata (different views)
One conceptual schema (all entitie/attritutes/relationships)
One internal schema (low-level description, storage, indexes etc)
DB instance
The data in the database at a particular point in time, changes whenever data is edited
Logical data independence
External schemata remain the same if we change the logical structure on the conceptual level
Physical data independence
Conceptual schema remains the same if we change the internal schema (data structures, algorithms)
Conceptual design phase
Construct a first, high-level model of the data
Uses entity-relationship modelling
Identify the entities, attributes, relationships and constraints
Based on users’ requirements
Independent of any physical considerations
Logical design phase
Construct the relational data model (the actual tables, e.g. Students, Courses, StudentCourses)
Normalisation takes place
Physical design
Describe the implementation of the logical design (storage structures, access methods, security)
Optimise for performance
Relation
Table with rows and columns (e.g. Student)
Attribute
Named column in a table (e.g. surname)
Field
Tuple
A row in the table (e.g. S002, Jane, Doe)
Record
Domain of an attribute
Set of allowed values (e.g. positive integers, strings starting with capital letter)
- FROM