SQL Basics Flashcards

1
Q

What is a relational database?

A

A collection of tables where each table is related to one another in some way

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

What is a table comprised of?

A

Columns and rows/records

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

T/F: The primary key column can contain duplicate data

A

False

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

T/F: The primary key column can contain null values

A

False

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

Insert ‘Baby’ and ‘Domestic’ into a table called ‘departments’ which has two columns

A

insert into departments values ('Baby', 'Domestic');

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

Create a table called ‘departments’ with two columns, ‘department’ and ‘division’, which have type ‘varchar(100)’. Make the primary key ‘department’.

A
create table departments (
    department varchar(100),
    division varchar(100),
    primary key (department)
);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

T/F: You can have more than one primary key constraint in a table

A

False

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

T/F: You can have multiple columns acting as one primary key

A

True

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

What does ; do in a query?

A

It separates statements in one script

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

Write a WHERE clause that returns all ‘department’ values that start with ‘F’ and end with ‘e’

A

WHERE department like ‘F%e’;

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

Write a WHERE clause that returns all ‘salary’ values greater than 10

A

WHERE salary > 10;

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

Write a WHERE clause that returns values where ‘salary’ < 40000 and ‘department’ is either ‘Clothing’ or ‘Pharmacy’

A
WHERE 'salary' < 40000
AND (department = 'Pharmacy'
OR department = 'Clothing');
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Write a WHERE clause where ‘department’ does not equal ‘Sports’

A

WHERE NOT department = ‘Sports’;

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

What’s another way of writing negative assertion other than NOT?

A

!= or <>

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

Write a WHERE clause that returns all emails that are NULL

A

WHERE email IS NULL;

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

Write a WHERE clause that returns all emails that are not NULL

A

WHERE email IS NOT NULL;

17
Q

Write a WHERE clause that returns department values that equal ‘Sports’, ‘First Aid’, ‘Toys’, and ‘Garden’

A

WHERE department IN (‘Sports’, ‘First Aid’, ‘Toys’, ‘Garden’);

18
Q

T/F: BETWEEN 80 AND 100 is inclusive

A

True

19
Q

Write a WHERE clause that returns ‘salary’ between 80 and 100

A

WHERE salary BETWEEN 80 AND 100;

20
Q

How do you write comments in an SQL query?

A

Use – to comment out a line

21
Q

Write a clause that orders the result by employee_id in descending order

A

ORDER BY employee_id DESC

22
Q

Write a query that returns all the distinct ‘department’ values from the ‘employees’ table

A

SELECT DISTINCT department FROM employees

23
Q

What does ORDER BY 1 mean?

A

It sorts in ascending order based on the first column in the table

24
Q

Limit the returned results by 10 using two different methods

A

LIMIT 10
FETCH FIRST 10 ROWS ONLY

25
Q

Give an alias ‘hello there’ to ‘department’ in a query

A

SELECT department as ‘hello there’

26
Q

T/F: AS is required to alias columns

A

False, you can omit it entirely

27
Q

What’s wrong with this query?
~~~
SELECT MAX(salary), MIN(salary)
WHERE last_name != ‘Wilson’
FROM professors
~~~

A

The WHERE clause needs to be AFTER the FROM clause