Databases and SQL Flashcards

1
Q

What is a data model?

A

An abstract description of the essential data within a given context and how data is related.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an entity?

A

A distinct thing about which data must be stored.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an attribute?

A

A single property or piece of information of an entity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is data modelling?

A

The process of producing an abstract model that represents the organisation and structure of the data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What problems exist in a flat-file database?

A

1) Data redundancy
2) Data inconsistency

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an entity identifier?

A

An attribute or combination of attributes that uniquely identify each instance of an entity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How is information from a flat-file database represented?

A

A single table with columns for each attribute and each row representing a new instance of each entity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a composite key?

A

Multiple attributes are combined to form the table’s entity identifier

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What information is stored in a entity description?

A

Entity name, primary key and attributes
(entity is always singular)

EntityName( PrimaryKey , Attribute1)
- primary key must be underlined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to create a table in SQL?

A

CREATE TABLE table_name (
primaryAttribute DATATYPE PRIMARY KEY,
attribute2 DATATYPE NOT NULL
);
- remember that you can write NOT NULL, DEFAULT constraints

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an entity-relationship diagram used for?

A

E-R diagrams are used to graphically represent the relationships between tables in a database

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can we tell from an entity description what the E-R diagram looks like?

A

The table which contains a foreign key of the other table holds the “many” side of the relationships.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Understanding E-R relationships

A
  1. One-to-many: one tutor, many students (and each student has one tutor)
  2. Many-to-many: one teacher, many pupils - one student, many teachers
  3. One-to-one: one school, one headteacher
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are flat-file databases?

A
  • simple ways of storing data in a text file such as CSV
  • each line is a record with fields separated by commas
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are advantages and disadvantages of flat-file databases?

A

+ easy to create and use for datasets
- inefficient to analyse data and gain insight and dataset grows

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a relational database?

A

A collection of tables with relationships created through common attributes, namely primary and foreign keys.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What data types are supported in SQL?

A

1) INTEGER
2) FLOAT
3) TEXT
4) VARCHAR(x) where x is the length
5) DATETIME
6) BOOLEAN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How to insert a new record into a table in SQL?

A

INSERT INTO table_name
VALUES (field1val, field2val…);

19
Q

How to select a record from a table in SQL?

A

SELECT FieldName
FROM TableName
INNER JOIN OtherTableName
ON TableName.ForeignKey = OtherTableName.PrimaryKey
WHERE Field1 = condition
ORDERBY ASC/DESC

20
Q

What is the wildcard symbol and what does it do?

A

*
returns all fields

21
Q

How to use LIKE in SQL?

A

For conditions:
WHERE FieldName LIKE ‘word%’
- make sure to use single quotation around word
- if % after, word starts with that
- if % before, word ends with that
- if % before and after, words contained in the text

22
Q

Date range shortcut

A

for a given age range starting 1/1/25 ending 31/1/25 :
WHERE StartDate < #2025/01/31# AND EndDate > #2025/01/31#

say not equal to default date if needs be

23
Q

What properties do fully normalised databases have?

A

All non-key attributes depend upon the key, the whole key and nothing but the key (and have no repeating groups).

24
Q

What are the advantages to having a fully normalised database?

A

1) Eliminate data redundancy
2) Eliminate data inconsistency
3) Limit unnecessary data duplication

25
What are the problems of data redundancy?
- increase storage costs (larger storage capacity needed) - reduced performance (slower queries)
26
What issues arise with data inconsistency?
- data is no longer **reliable** - can occur from update, insertion or deletion anomalies
27
What is database normalisation?
The process of organising data into **related tables** so each piece of data is **only stored once**.
28
What are many-to-many relationship indicative of?
- Lack of database normalisation - repeating groups
29
What is a client server database?
A database that allows **simultaneous access** to a single, central database from **multiple clients**.
30
How do clients access client-server databases?
**Client applications** that are installed locally on users' computers.
31
What are benefits of client-server databases?
- all users have access to **same, up-to-date data** - data accessed from anywhere **without duplicating and distributing data** - **less data redundancy** and hence lower risk of **data integrity issues** - centrally managed data that can be mined for analysis
32
What are issues with client-server databases?
- data inaccessible if central server is unavailable - simultaneous access can cause congestion and poor performance - multiple access for same resources need to be handled
33
What issues occur with concurrent access?
**Data integrity issues** due to **insertion anomalies** and **lost updates**.
34
What is an insertion anomaly?
Two clients insert records simultaneously that are logically inconsistent.
35
What are lost updates?
Two clients or transactions access the **same record** to update at the **same time**, which can lead to the earlier update being overridden by the later update.
36
What is a transaction?
A single unit of work in a databases (which changes the databases when **committed** to the database).
37
How to manage the lost update problems and issues with concurrent access generally?
- Record Locks - Serialisation: 1) Timestamp ordering 2) Transaction queueing 3) Commitment ordering
38
What happens in record locks?
Maintains information about which records are being **accessed** at any times and **prevents any transactions to the record** that can compromise data integrity in this time. *Read lock = no writing transactions Write lock = no reading or writing transactions*
39
What issues occur with record locks?
1) Deadlock: two transactions have placed locks on records that their updates are dependent on 2) Performance issues: other users are forced to wait
40
What is serialisation?
Applies transactions to a database in a **logical order**.
41
How does timestamp ordering work?
- Timestamp is associated by transaction when it begins - Records timestamp of last successful read or write - Applies rules before committing to database to check if data integrity will be lost - If it will, abandon transaction
42
How does transaction queueing work?
- Groups updates into transaction - Adds transaction to a processing **queue** - uses FIFO for committing transactions This can lead to reduced performance and longer waiting times
43
How does commitment ordering work?
- Software tracks conflicts between transactions - Applies transactions in an order that reduces conflicts and reduces data inconsistency - Can lead to transactions being delayed and abandoned if leads to issues