4.10 Databases Flashcards

1
Q

What is an entity?

A

An entity is the object / thing of interest about which data is to be recorded (a table in SQL).

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

What is an attribute?

A

An attribute is property of an entity (a field in SQL).

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

What is a relationship?

A

A relationship is the link or association between entities (primary keys ←→ foreign keys)

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

What is a key (in a database)?

A
  • A key is the name given to a special field in a database where the values in the field can be used to identify particular records, e.g. CustomerID.
  • Sometimes a field that is already in the database can be used as the key field.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a primary key?

A

A key which has a unique value for each record, and acts as a unique identifier for each record

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

3 problems with a flat file database

A
  1. One small change can involve tediously changing many records
  2. Deleting the only instance of a record containing a particular category will also delete that category
  3. You can’t add a new category until you create a record that contains that particular category
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you solve the problems with flat file databases?

A
  • Relational databases that are made up of two or more linked tables.
  • Linked tables can be used to find records which are linked together by using the value of the shared key column. They are a feature of relational databases.
  • This shared key column acts as the primary key in the table in which its defined, and as a foreign key in the table it is used.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a flat file database?

A

A simple store of information
- Columns are called fields
- Rows are called records
- A table is a group of records

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

What is a composite key?

A

A key composed of two or more attributes that together uniquely identify a record.

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

When is normalisation (database) achieved?

A
  • When there is no redundant data and all related data is stored together
  • (When each attribute depends on the key, the whole key and nothing but the key)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the saying for database normalisation?

A

“Each attribute must depend on the key, the whole key, and nothing but the key”

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

Requirements for 1st normal form

A
  1. Every record has a primary key
  2. No repeating groups → must include a copy of the primary key in the new table (creating a composite key)
  3. The data in each field must be atomic (i.e. data cannot be sensibly subdivided e.g. name → fname & sname)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a repeating group?

A

A set of attributes whose structure repeats between rows

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

Requirements for 2nd normal form

A

No partial dependencies
this means…
- Do all nonkey attributes depend on all parts of the composite key?
- If not, take them out and create a new entity.
(So check all tables with composite keys)

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

Requirements for 3rd normal form

A

No non-key dependencies
- All non-key attributes are checked to see if they are only dependent on the primary key.

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

How do you identify the key in an entity relationship diagram?

A

Underlining

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

SQL: Create a database called school

A

CREATE DATABASE school

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

What does DDL stand for (in SQL)?

A

Data Definition Language

19
Q

SQL: Create a table called students
(StudentNumber as primary key, forename, surname, and date of birth)

A

CREATE TABLE students
(
StudentNumber INT(8) PRIMARY KEY,
forename VARCHAR(32),
surname VARCHAR(32),
DateOfBirth DATE
)

20
Q

SQL: What is the keyword for deleting a database/table?

21
Q

SQL data types

A

CHAR(size) // → fixed length string
VARCHAR(size) // → string (with a maximum length)
ENUM // → string object that has to be chosen from a list of possible values
BOOL / BOOLEAN
INT(size) // → size is the number of digits
FLOAT(size,d) // → size is the number of digits , with d digits after the decimal point
DATE
TIME
DATETIME

22
Q

What does DML stand for (in SQL)?

A

Data manipulation language

23
Q

SQL: all strings beginning with ‘str’

A

LIKE ‘str%’

24
Q

SQL: Any strings at least five characters long

A

LIKE ‘_____%’

25
SQL: between two numbers
... WHERE StudentNumber BETWEEN 10 AND 100
26
SQL: Selecting from two tables
SELECT table1.attributeX , table2.attributeY FROM table1 , table2 WHERE table1.primarykey = table2.foreignkey AND ...
27
SQL: ordering results
ORDER BY surname ORDER BY surname ASC ORDER BY surname DESC
28
SQL: Inserting data
INSERT INTO students VALUES(__,__),(__,__),(__,__) INSERT INTO students (surname , forename) VALUES (__... //if you can't remember what order you're supposed to do it in)
29
SQL: update a forename to 'Harry' where...:
UPDATE students SET forename = ‘Harry' WHERE...
30
SQL: Delete record
DELETE FROM students WHERE ...
31
What is the purpose of a client server database?
To provide simultaneous access to a database for multiple clients
32
Why does concurrent access need to be managed in a client server database?
To preserve the integrity of the database
33
State one problem that concurrent access could result in
Updates could be lost if two clients edit a record at the same time
34
4 ways to manage concurrent access
1. Record locks 2. Serialisation 3. Timestamp ordering 4. Commitment ordering
35
What does it mean for a schedule of transactions to be serialised?
If the schedule of transactions has the same effect as an **equivalent serial schedule**
36
What is a transaction?
A set of operations that are grouped together as a single logical unit
37
Why is serialisation useful?
It allows us to interleave and overlap operations within multiple transactions, reducing the time taken for transactions to be completed
38
How does record locking work?
- When a transaction on a record starts, a lock is set on the record - Other transactions cannot access the record until the lock is released
39
2 disadvantages of record locking
* Slows the system down slightly * Can lead to deadlock
40
How does timestamp ordering work? (2•)
- Timestamps are generated **for each transaction**. These timestamps indicate the order transactions occurred in - The database server applies **rules** to determine if processing a transaction **will result in loss of data integrity**, and if so aborts the transaction
41
2 situations in timestamp ordering when a transaction would be aborted
* If transactions is trying to **write** to a record: * then when the **read or write timestamp** on the record is greater that the time at which the transaction started * If transactions is trying to **read** a record: * then when the **write timestamp** on the record is greater that the time at which the transaction started
42
When can a transaction be committed?
When all of its operations have been carried out
43
What is commitment ordering?
Using an algorithm to determine an **optimum order** to commit half-complete transactions in order to reduce conflicts and deadlocks
44
What is a foreign key?
The primary key field of one table that appears in another table to make a link between the tables