SQL Flashcards

1
Q

What are some differences between SQL and NoSQL?

A

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.

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

What is normalization?

A

A technique of not storing duplicate information but instead storing a reference to it, like SQL storing photos in a separate table

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

What is denormalization?

A

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

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

What is a transaction?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a RDBMS?

A

Relational database management system (Oracle)

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

What is a schema?

A

The description of the organization of a database table, columns, and data types

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

What is the difference between static typing and dynamic typing?

A

Static requires you to specify the type of data upfront

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

List some common SQL datatypes

A
  • Boolean
  • INT
  • FLOAT
  • VARCHAR (255)
  • TEXT (unlimited length)
  • DATE
  • DATETIME
  • TIME
  • BLOB (binary data; eg an image)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a foreign key?

A

A value in a database table whose responsibility is to point to a row in a different table.

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

What does SQL stand for?

A

Structured query language. It’s a domain-specific language to query data out of relational databases.

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

What are the comparision and equality operators in SQL?

A

(, >=, <=, =, !=)

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

What are the boolean operators in SQL?

A

(AND, OR, NOT)

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

Provide an example of a SQL Select

A
SELECT
  *
FROM
  users
WHERE
  name = 'Ned';
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Provide an example of a SQL Insert

A

INSERT INTO
users (name, age, height_in_inches)
VALUES
(‘Santa Claus’, 876, 34);

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

Provide an example of a SQL Update

A
UPDATE
  users
SET
  name = 'Eddard Stark', house = 'Winterfell'
WHERE
  name = 'Ned Stark';
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Provide an example of a SQL Delete

A
DELETE FROM
  users
WHERE
  (name = 'Eddard Stark' AND house = 'Winterfell');
---
DELETE FROM
  accounts
WHERE
  customer_id = 666;
17
Q

Provide an example of creating a users table

A
CREATE TABLE users (
  id INTEGER PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  birth_date DATE,
  house VARCHAR(255),
  favorite_food VARCHAR(20)
);
18
Q

What considerations do we need on a self-join?

A

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

19
Q

What formatting would we use on a subquery table?

A
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
  )
20
Q

How should we handle NULL comparisons in SQL?

A

We want to use IS NULL or IS NOT NULL instead of == or !=