SQL Flashcards

1
Q

Why do we use SQL?

A

Flexible
Breaks into relational algebra
Very high level

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

What are the 3 types of SQL?

A

DDL - schema/constraint data
DML - insert/delete/modify data
DQL - find/join/aggregate data

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

How do we order SQL statements?

A

SELECT desired attributes
FROM one or more tables
WHERE condition about table rows

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

How do we do selection and projection in SQL?

A
Selection = WHERE
Projection = SELECT all attributes of relation below
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do we rename columns in SQL?

A

AS

Renames attribute

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

How do we do computed attributes in SQL?

A

Use a calculation

Part of SELECT clause

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

How are NULL values used in SQL?

A

Tuples can be NULL

Any value compared with NULL = truth value unknown

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

How do we do 3 valued logic in SQL?

A
True = 1
Also = 0
Unknown = 0.5
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do we do multi-relation queries in SQL?

A

Combine data from multiple queries

List all in FROM clause

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

How do we do subqueries/nested queries in SQL?

A

SELECT-FROM-WHERE statements

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

How do we do HAVING statements in SQL?

A

HAVING

Follows GROUP BY clause

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

What are the 3 formal semantics of SQL?

A

Product of relations in FROM clause
Apply selection condition from WHERE clause
Project onto list of attributes/expressions in SELECT clause

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

How do we do explicit tuple variables in SQL?

A

Query needs to use 2 copies of same relation

Distinguish by putting relation name then tuple name in FROM clause

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

How do we do the EXISTS operator in SQL?

A

EXISTS

True if and only if is not empty

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

How do we do union/intersection/difference in SQL?

A

Default set semantics (duplicates deleted)

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

How do we do the different types of joins in SQL?

A

Natural join: R natural join S
Product: R cross join S
Theta join: R join S on
Outer join: R outerjoin S

17
Q

How do we do the ANY operator in SQL?

A

X = ANY

Boolean true if x equals at least 1 tuple in relation

18
Q

How do we do the ALL operator in SQL?

A

X<>ALL

True for every tuple t in relation: (x not equal to t)

19
Q

How do we do aggregations in SQL?

A

SUM, AVG, COUNT, MIN, MAX applied to column in SELECT clause
To eliminate duplicates use DISTINCT
Ignore NULLS
To restrict on SELECT each element must be aggregated or attribute on GROUP BY list