Databases Flashcards

1
Q

What is a database?

A

An easier way to store data for humans to read.

They are used by organisations to CRUD:

Create
Retrieve
Update
Delete

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

Why do organisations use them?

A

Security - manage who has access & what type

Size/scalability

Accuracy - create rules so incorrect data / data formats cannot be entered

Redundancy - having multiple copies

No clashing - can lock others out so two people can’t edit the same thing at the same time (reduce risk of error)

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

What is a relational database

A

A type of database that maps data via the relationships between different tables.

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

What are used to map this data?

A

Primary keys & Foreign keys

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

What is the benefit of using a combination of relational & non relational databases

A

Non relational are better at ingesting a lot of data fast (hot data). Therefore companies can use this type of database to capture a lot of data at once, then move it to a relational database later on to do something with that data that is better for analytics

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

What is a non-relational database?

A

Good for key value pairs.

E.G. given x ID give me that value.

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

What is ACID compliance?

A

A set of properties that guarantees database transactions are processed RELIABLY.

Guarantees validity even in the event of errors, power failures etc.

Atomicity - the “all or nothing” rule — the transaction either happens completely or doesn’t happen at all

Consistency - data is consistent before and after a transaction without any missing steps. e.g. if you don’t have 10 inserts for the 10 columns, the query will fail.

Isolation - multiple transactions can happen at the same time creating incorrect data in the database

Durability - transactional success is robust to system failure, e.g. if a database turned off and then got turned off a day later, all logs would still be there.

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

What is an ERD / what does it stand for?

A

Entity Relationship Diagram.

A way of drawing out the structures in a database and the relationships between the tables.

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

What are the different types of database relationships?

A

One-to-One

One-to-Many (most common)
- e.g. one user has many tasks (to do app)

Many-to-Many

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

How did the one to many ERD look for your database?

A

Table: User
userID (PK)
username

Table: Tasks
taskID (PK)
description 
completed
userId (FK) - this is what links the two database tables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are primary & foreign keys?

A

Primary Key = the unique id for a row within a database table (think uuid)
- every row in a relational database will have a primary key and it MUST be unique

The primary key constraints are used to enforce entity integrity.

Foreign Key = what relates the tables eg. user id in user & task

A FOREIGN KEY constraint prevents any actions that would destroy links between tables with the corresponding data values

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

What is meant by a transaction?

A

A sequence of database operations that satisfies the ACID properties

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

Why SQL?

A

Pros:
Great with relational data
Has a table structure
Been around for longer - reliable

Cons:
Inflexible
Requires a schema

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

What is a database schema?

A

The structure of the database.

This is usually done ahead of creating the database, as SQL works best when you have a solid idea of what your tables will l
look like & the relationships between them.

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

Why NoSQL? E.G. MongoDB

A

Pros:
More flexible to change
Scales horizontally
Has a document structure

Cons:
Not great with complex relationships
It’s new so is subject to lots of changes

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

How do you insert data into your table?

A

INSERT INTO table_name (col1, col2, col3)
VALUES (val1, val2, val3)

Note: if you are entering data for all columns, you don’t need to specify them in the first line

17
Q

How do you create a table?

A
CREATE TABLE  products (
id INT NOT NULL,
name STRING,
price MONEY,
PRIMARY KEY (id)
)
18
Q

What does SELECT * FROM ‘products’ mean?

A

It would show you all data in your table.

19
Q

What does the WHERE keyword do?

A

Allow us to select the pieces of data we need by defining a criteria

E.G. WHERE id = 1