SQL

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/39

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

40 Terms

1
New cards

UNION

A SQL operation that combines the results of two or more SELECT statements into a single result set, eliminating duplicate rows.

2
New cards

UNION ALL

A SQL operation similar to UNION, but it includes all rows from the combined result sets, including duplicates.

3
New cards

INTERSECT

A SQL operation that returns only the rows that are present in both of the result sets from two or more SELECT statements.

4
New cards

EXCEPT

A SQL operation that returns all rows from the first result set that are not present in the second result set, effectively subtracting the results of one query from another.

5
New cards

FULL JOIN

A SQL operation that combines rows from two or more tables based on a related column, returning all records when there is a match in either table and filling with NULLs where there is no match.

6
New cards

CAST

A SQL function that converts an expression from one data type to another, allowing for data type compatibility in operations and queries.

CAST( field AS type)

7
New cards
<p>NOT NULL constraint</p>

NOT NULL constraint

A SQL constraint that ensures a column cannot have a NULL value, enforcing that every record must contain a value for that column.

8
New cards
<p>ALTER TABLE</p>

ALTER TABLE

A SQL command used to modify the structure of an existing table, allowing for changes such as adding, deleting, or modifying columns and constraints.

9
New cards
<p>ADD COLUMN</p>

ADD COLUMN

A SQL command used to add a new column to an existing table within a database, specifying the column name and data type.

10
New cards
<p>REFERENCES table (column)</p>

REFERENCES table (column)

A SQL constraint used in defining foreign keys that establishes a link between the current table and a column in another table, ensuring referential integrity.

11
New cards
<p>RENAME column to new_column_name</p>

RENAME column to new_column_name

A SQL command used to change the name of an existing column in a table to a new specified name.

12
New cards
<pre><code class="language-sql">ADD CONSTRAINT table1_table2_fkey FOREIGN KEY (id) REFERENCES table (id)</code></pre><p></p>
ADD CONSTRAINT table1_table2_fkey FOREIGN KEY (id) REFERENCES table (id)

A SQL command used to add a foreign key constraint to a table, linking a specified column in the current table to a column in another table, thereby enforcing referential integrity.

13
New cards
UPDATE table_a
SET column_to_update = table_b.column_to_update_from
FROM table_b
WHERE condition1 AND condition2 AND ...;

This query does the following:

  1. For each row in table_a, find the corresponding row in table_b where condition1, condition2, etc., are met.

  2. Set the value of column_to_update to the value of column_to_update_from (from that corresponding row).

The conditions usually compare other columns of both tables, e.g. table_a.some_column = table_b.some_column. Of course, this query only makes sense if there is only one matching row in table_b.

14
New cards
-- Update professor_id to professors.id where firstname, lastname correspond to rows in professors
UPDATE affiliations
SET professor_id = professors.id
FROM professors
WHERE affiliations.firstname = professors.firstname AND affiliations.lastname = professors.lastname;

Example: This SQL command updates the professor_id in the affiliations table to match the id from the professors table, based on matching firstname and lastname values. It also selects the first 10 rows from the affiliations table for review.

15
New cards
<p>Referential Integrity Violation</p>

Referential Integrity Violation

Occurs when a foreign key constraint is violated, meaning a value in a foreign key column does not match any value in the referenced primary key column of another table.

16
New cards
-- Identify the correct constraint name
SELECT constraint_name, table_name, constraint_type
FROM information_schema.table_constraints
WHERE constraint_type = 'FOREIGN KEY';

-- Drop the right foreign key constraint
ALTER TABLE affiliations
DROP CONSTRAINT affiliations_organization_id_fkey;

-- Add a new foreign key constraint from affiliations to organizations which cascades deletion
ALTER TABLE affiliations
ADD CONSTRAINT affiliations_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations (id) ON DELETE CASCADE;

Changing how Referential Integrity Violation is enforced by defining or modifying foreign key constraints between tables to ensure that relationships are maintained.

17
New cards

OLTP

Online Transaction Processing | Purpose: Support day to day operation | Tasks: Update latest customer transaction

18
New cards

OLAP

Online Analytical Processing | Purpose: Support business decision making | Tasks: Find the most loyal customers

19
New cards
<p></p>

Distinguish the difference between OLTP vs OLAP

20
New cards
term image

OLTP & OLAP influence on each other

21
New cards
term image

ETL vs ELT visual

22
New cards

Tool

Purpose

Modeling Style

Architect Focus

Cogito

Real-time analytics

Minimal, in-memory

Support real-time models, dashboards

Clarity

Raw data extraction (SQL)

Normalized (3NF)

ETL design, data mapping, integrity

Caboodle

Enterprise reporting (EDW)

Dimensional modeling

Subject-area modeling, SCDs, performance

Cogito vs Clarity vs Caboodle

23
New cards
term image

Conceptual vs Logical vs Physical data model

24
New cards

Star Schema

Dimensional modelingapproach used in data warehousing that organizes data into fact and dimension tables for efficient querying.

25
New cards
<p></p>

FORIEGN KEY function

26
New cards
-- Create a new table for dim_author with an author column
CREATE TABLE dim_author (
    author varchar(256)  NOT NULL
);

-- Insert authors 
INSERT INTO dim_author
SELECT DISTINCT author FROM dim_book_star;

-- Add a primary key 
ALTER TABLE dim_author ADD COLUMN author_id SERIAL PRIMARY KEY;

-- Output the new table
SELECT * FROM dim_author;

Create a new table. Add a new column. Insert value.

27
New cards
term image

Denormalized = Star Schema. Normalized = Snowflake Schema

28
New cards
term image

Normalization in OLTP vs OLAP

29
New cards
term image

Query for viewing views

30
New cards
term image

Creating view example

31
New cards
term image

Grant/revoke view access

<p>Grant/revoke view access</p>
32
New cards
term image

Data Warehouse vs Data Mart vs Data Lake

33
New cards
term image

Snowflake SQL functions

34
New cards
term image

Why Lateral instead of regular join

35
New cards
term image

Snowflake SQL query history

36
New cards
term image

Snowflake SQL storing JSON data

37
New cards
term image

PARSE JSON example

38
New cards
term image

OBJECT CONSTRUCT example

39
New cards
term image

Nested JSON dot vs colon

40
New cards