SQL Flashcards

1
Q

SQL combines features of what 3 things?

A
  1. DDL (Data Definition Language)
  2. DML (Data Manipulation Language)
  3. DCL (Data Control Language)

DMC

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

What does CREATE TABLE statement do in SQL?

A

Defines a table schema, including:
* Attributes
* Constraints
* Default values

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

How does SQL handle NULL values?

A

Using three-valued logic: TRUE, FALSE, and UNKNOWN

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

What is the difference between PRIMARY KEY and UNIQUE?

A
  • PRIMARY KEY: ensures uniqueness and non-null values for a single attribute
  • UNIQUE: Allows nulls and can apply to multiple attributes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the purpose of the WHERE clause

A

Filter rows based on conditions in SELECT, UPDATE and DELETE statements

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

COUNT(*) vs COUNT(column)

A

‘*’ - counts all rows
column - Excludes NULL values in the specified column

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

What is an inner join?

A

Combines rows from two tables where there is a match on the join condition

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

Left Outer Join

A

Combines rows from two tables including all the rows from the first table, even if there is no match in the second. (NULLs in right table)

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

What is the purpose of the GROUP BY clause

A

Groups rows with identical values (in specified columns) for aggregate calculations

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

How does the HAVING clause differ from WHERE?

A

WHERE filters before aggregation, HAVING filters after aggregation

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

What is a view in SQL

A

Virtual table created by storing a query, dynamically evaluated each time it is referenced

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

Subquery vs CTE

A
  • Subquery is embedded within another query
  • CTE is temporary result set with a name, used for readability and reuse
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Funcitonal dependency

A

Relationship where one attribute uniquely determines another

plantCode —> plantName

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

Main goals of normalization

A
  1. eliminate redundancy
  2. prevent anomalies
  3. ensure data consistency
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

DISTINCT

A

Removes duplicate rows from query result

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

How do aggregate functions handle NULL values?

A

They ignore NULLs unless explicity included using COUNT(*)