SQL Flashcards
(20 cards)
What are some differences between SQL and NoSQL?
NoSQL(document-oriented storage) stores data in graphs, kv pairs, or documents (similar to JSON). Documents are stored in collections that are similar to SQL’s tables to hold related entries. No schema or restrictions to particular columns or fields.
What is normalization?
A technique of not storing duplicate information but instead storing a reference to it, like SQL storing photos in a separate table
What is denormalization?
NoSQL where a single query can retrieve all the information we need however data is duplicated so if we want to update we need to change the same thing in multiple places
What is a transaction?
- A unit of work performed against a database. All work in the transaction must succeed or it’s rolled back. “All or nothing”
- We can trust our data is consistent across tables because operations are in a transaction
What is a RDBMS?
Relational database management system (Oracle)
What is a schema?
The description of the organization of a database table, columns, and data types
What is the difference between static typing and dynamic typing?
Static requires you to specify the type of data upfront
List some common SQL datatypes
- Boolean
- INT
- FLOAT
- VARCHAR (255)
- TEXT (unlimited length)
- DATE
- DATETIME
- TIME
- BLOB (binary data; eg an image)
What is a foreign key?
A value in a database table whose responsibility is to point to a row in a different table.
What does SQL stand for?
Structured query language. It’s a domain-specific language to query data out of relational databases.
What are the comparision and equality operators in SQL?
(, >=, <=, =, !=)
What are the boolean operators in SQL?
(AND, OR, NOT)
Provide an example of a SQL Select
SELECT * FROM users WHERE name = 'Ned';
Provide an example of a SQL Insert
INSERT INTO
users (name, age, height_in_inches)
VALUES
(‘Santa Claus’, 876, 34);
Provide an example of a SQL Update
UPDATE users SET name = 'Eddard Stark', house = 'Winterfell' WHERE name = 'Ned Stark';
Provide an example of a SQL Delete
DELETE FROM users WHERE (name = 'Eddard Stark' AND house = 'Winterfell'); --- DELETE FROM accounts WHERE customer_id = 666;
Provide an example of creating a users table
CREATE TABLE users ( id INTEGER PRIMARY KEY, name VARCHAR(100) NOT NULL, birth_date DATE, house VARCHAR(255), favorite_food VARCHAR(20) );
What considerations do we need on a self-join?
We should use aliases to make it clear what is being joined
SELECT
team_member.first_name, team_member.last_name,
manager.first_name, manager.last_name
FROM
employee AS team_member
JOIN
employee AS manager ON manager.id = team_member.manager_id
What formatting would we use on a subquery table?
SELECT bands.* FROM bands JOIN ( SELECT albums.* FROM albums WHERE album.type = "POP" GROUP BY album.band_id HAVING COUNT(*) > 3 ) AS pop_group_albums ON bands.id = pop_group_albums.band_id WHERE band.leader_id IN ( SELECT musicians.id FROM musicians WHERE musicians.birth_yr > 1940 )
How should we handle NULL comparisons in SQL?
We want to use IS NULL or IS NOT NULL instead of == or !=