Chapter 2 - Data Models & Query Languages Flashcards
Describe the relational data model
Data is organized into relations (called tables in SQL) where each relation is an unordered collection of tuples (rows in SQL)
What are the driving forces behind the adoption of NoSQL databases?
- A need for greater scalability than relational databases can easly achieve including large datasets and high write throughput
- Specialized query operations that are not well supported by the relational model
- Desire for more dyanmic and expressive data models
- Impedance mistmatch
What is impedance mismatch?
Impedance mismatch refers to the disconnect between object-oriented programming and relational databases. An awkward transition layer is required between the objects in the application code and the database model of tables, rows and columns.
What advantages does a JSON data model have over a relational data model?
- Reduces impedance mismach
- Better locality: If you want to fetch all the relevant information is in one place and one query is sufficient
- Easier to edit schema: ALTER TABLE and UPDATE statements can take very long fr large tables as MySQL copies who table for ALTER TABLE and UPDATE must rewrite every row
What are some advantages of making a field an “ID” with the data stored in a separate table as oppose to a plain-text string?
- Consistent spelling and style
- Ease of update - string stored in one place so easy to update in one place
- more…
What disadvantages do JSON and other document databases have?
Poor support for many-to-many and many-to-one (e.g multiple people with the same school). The database will have either redundant data (data about the school stored in each object) or the developers will manally resolve references from one record to another.
In relational databases, what is the query optimizer?
The query optimizer automatically decides which parts of the query to execute in which order and which indexes to use.
What is the relational technique of shredding?
Shredding is splitting a document-like structure into multiple tables
It may lead to cumbersome schemas and unnecessarily complicate application code
What is the difference between and imperative and a declarative language and which is SQL?
An imperative language tells the computer to perform certain operations in a certain order. A declarative language specifies the pattern of data desires and conditions that must be met but not how to achieve that goals.
SQL is a declarative language.
What are the advantages of declarative query languages?
The database can move records around safely and make other similar optimisations without potentially breaking queries