Databases Flashcards
What is a database?
An easier way to store data for humans to read.
They are used by organisations to CRUD:
Create
Retrieve
Update
Delete
Why do organisations use them?
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)
What is a relational database
A type of database that maps data via the relationships between different tables.
What are used to map this data?
Primary keys & Foreign keys
What is the benefit of using a combination of relational & non relational databases
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
What is a non-relational database?
Good for key value pairs.
E.G. given x ID give me that value.
What is ACID compliance?
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.
What is an ERD / what does it stand for?
Entity Relationship Diagram.
A way of drawing out the structures in a database and the relationships between the tables.
What are the different types of database relationships?
One-to-One
One-to-Many (most common)
- e.g. one user has many tasks (to do app)
Many-to-Many
How did the one to many ERD look for your database?
Table: User
userID (PK)
username
Table: Tasks taskID (PK) description completed userId (FK) - this is what links the two database tables
What are primary & foreign keys?
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
What is meant by a transaction?
A sequence of database operations that satisfies the ACID properties
Why SQL?
Pros:
Great with relational data
Has a table structure
Been around for longer - reliable
Cons:
Inflexible
Requires a schema
What is a database schema?
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.
Why NoSQL? E.G. MongoDB
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