Databases / Data Flashcards

(26 cards)

1
Q

Schema

A

Blueprint / structure of DB.

Key Components
- Tables
- Columns/fields
- Views
- Indexes

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

Benefits of having multiple DB Schemas

A
  • Allows for better organization
  • Separation of DB objects into logical groupings
  • Easier to manage
  • Security and access control allowing for fine-grained control of who can access the data
  • Modularity: Schemas can represent diff modules / components of an application allowing for modular design and development
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Flyway

A

Open source DB migration tool that helps manage changes to a DB. (Similar to GIT)

Helps keep DB in sync, organized and consistent.

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

Flyway Versioned Migrations

A

Uses versioning mechanism to apply migrations in a specific order. Each is given a unique version number

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

Benefits of Flyway

A
  • Automates the process of applying DB migrations
  • Ensures same migrations are applied in same order across all env
  • Version control making it easy to track changes over time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

DB Object

A

Any defined obj in a DB that can store or reference data.

Created using Data Definition Language (DDL) like CREATE, ALTER, DROP

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

DB Object Examples

A
  • Tables: rows and columns
  • Views: virtual tables representing the result of a stored query
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Views

A

Virtual tables defined by a query

  • simplify complex’s queries
  • encapsulate complex logic
  • present data in a specific format without altering underlying tables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

View Details

A

Views do not store data but dynamically generate results based on the query when accessed

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

What 4 properties a transaction must exhibit

A

ACID

  • Atomicity: ensures all operations are completed successfully. If any operations fail the transaction is rolled back and DB is left unchanged
  • Consistency: guarantees a transaction will bring the DB from one valid state to another
  • Isolation: ensures that all operations of a transaction are isolated from others. Intermediate states within a transaction are not visible to other transactions
  • Durability: ensures changes by a committed transaction are permanent even in the case of system failure
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

DB Transactions

A

A sequence of operations performed as a single logical unit of work

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

Example Transaction Scenario

A
  1. Begin Transaction

BEGIN;

  1. Debit amount from account A

UPDATE accounts SET balance = 200;

  1. Update amount from account B

UPDATE accounts SET balance = 1;

  1. Commit Transaction

COMMIT;

** If the debit operation fails the transaction is rolled back

ROLLBACK

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

unnest

A

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.

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

unions

A

used to combine the result of two or more select statements

  • if one part fails the entire query fails
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Compound Key

A

Also known as a composite key

  • A key in a DB table that consists of 2 or more columns which together uniquely identify a record in a table
  • Used when a single column isn’t sufficient to uniquely identify a record

EX:
CREATE TABLE OrderItems (
OrderID INT,
ProductID INT,
Quantity INT,
PRIMARY KEY (OrderID, ProductID)
);

OrderId and ProductID together form the compound key.

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

Graph DB

A
  • designed to store and manage data as nodes (entities) and edges (relationships)
  • optimized for complex relationships and interconnected data
17
Q

Graph DB Nodes

A

Represents entities like people, products, cities

18
Q

Graph DB Edges

A

Represents relationships between notes like friend of, bought, located in

19
Q

Graph DB Properties

A

Attributes associated with nodes or edges

20
Q

Graph DB Traversal

A

Querying the DB by following relationships between nodes

21
Q

Graph DB Advantages

A
  • efficient relationship handling like recommendation handler
  • flexible schema by allowing dynamic changes without rigid table structures
  • fast queries on connected data
22
Q

Popular Graph DBs

A

Amazon Neptune

23
Q

When to use a graph DB

A
  • friend recommendations
  • analyzing social interactions
  • finding influencers in a network
  • fraud detection
24
Q

Composite Table

A

Store data usually FKs to represent complex relationships and the ability to uniquely identify a row

25
flyway.baselineOnMigrate
If set to true means if flyway detects an existing DB that hasn't been managed by flyway it will create a baseline version for it. This allows flyway to start managing the DB without trying to reapply old migrations. Simple terms: If the DB already exists, treat it as if it starts from a specific version so we don't mess up what's already there. For example, if your database is already at version 30, Flyway will skip versions 1–30 and only apply migrations starting from version 31.
26
flyway.table
Tells flyway what table name to use to keep tack of the migrations it has By default it uses flyway_schema_history. Flyway allows you to configure different tables for tracking migrations. Use Case: If you have multiple projects or modules (e.g., policy_data and base_policy_data) sharing the same database, you can use separate migration history tables to track their migrations independently.