SQL Keys and Joining Tables Flashcards

1
Q

What do PRIMARY KEY statements do?

A

provide a unique identifier for each row in a table

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

What is the basic PRIMARY KEY statement format?

A

CREATE TABLE table_name(column_name data_type PRIMARY KEY, column_name data_type…);

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

What is a foreign key?

A

a column that contains the primary key of another database

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

How do you specify a column that belongs to a specific table?

A

table_name.column_name

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

What do JOIN statements do?

A

combine two tables

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

What is an inner join?

A

combines two tables with all common values (i.e., ‘1,2,3,4’ corresponds to ‘1,2,3,4’

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

What is an outer join?

A

combines two tables with only SOME common values (i.e., ‘1,2,3,4’ joins with ‘1,2,5,6’)

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

What is the basic JOIN statement format?

A

SELECT * FROM table_name1 JOIN table_name2 ON table_name1.column_name = table_name2.column_name;

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

What is a LEFT or RIGHT join?

A

combine two tables in an outer join, but place ‘null’ values where items do not match

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

What do AS statements do?

A

rename a column with an “alias”, which can be useful when joining tables

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

What is the basic AS statement format?

A

table_name.column_name AS ‘alias’

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