Schema
Blueprint / structure of DB.
Key Components
- Tables
- Columns/fields
- Views
- Indexes
Benefits of having multiple DB Schemas
Flyway
Open source DB migration tool that helps manage changes to a DB. (Similar to GIT)
Helps keep DB in sync, organized and consistent.
Flyway Versioned Migrations
Uses versioning mechanism to apply migrations in a specific order. Each is given a unique version number
Benefits of Flyway
DB Object
Any defined obj in a DB that can store or reference data.
Created using Data Definition Language (DDL) like CREATE, ALTER, DROP
DB Object Examples
Views
Virtual tables defined by a query
View Details
Views do not store data but dynamically generate results based on the query when accessed
What 4 properties a transaction must exhibit
ACID
DB Transactions
A sequence of operations performed as a single logical unit of work
Example Transaction Scenario
BEGIN;
UPDATE accounts SET balance = 200;
UPDATE accounts SET balance = 1;
COMMIT;
** If the debit operation fails the transaction is rolled back
ROLLBACK
unnest
used to expand an array into a set of rows
“unnests” the array elements and returns them as individual rows
Used in replacement of writing multiple queries. Basically a bulk query.
unions
used to combine the result of two or more select statements
Compound Key
Also known as a composite key
EX:
CREATE TABLE OrderItems (
OrderID INT,
ProductID INT,
Quantity INT,
PRIMARY KEY (OrderID, ProductID)
);
OrderId and ProductID together form the compound key.
Graph DB
Graph DB Nodes
Represents entities like people, products, cities
Graph DB Edges
Represents relationships between notes like friend of, bought, located in
Graph DB Properties
Attributes associated with nodes or edges
Graph DB Traversal
Querying the DB by following relationships between nodes
Graph DB Advantages
Popular Graph DBs
Amazon Neptune
When to use a graph DB
Composite Table
Store data usually FKs to represent complex relationships and the ability to uniquely identify a row