SQL Flashcards

1
Q

How do you add a row to a SQL table?

A

insert into “tableName” (“columnName1”, “columnName2”, “columnName3”, “columnName4”)
values (‘valueForColumnName1’, ‘valueForColumnName2’, valueForColumnName3, ‘valueForColumnName4’);
returning *;

for values, text values go into single quotes; numbers do not

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

What is a tuple?

A

In SQL, a list of values is referred to as a tuple.

Source: sql-insert exercise documentation

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

How do you add multiple rows to a SQL table at once?

A

insert into “tableName” (“columnName1”, “columnName2”, “columnName3”, “columnName4”)
values (‘row1valueForColumnName1’, ‘row1valueForColumnName2’, row1valueForColumnName3, ‘row1valueForColumnName4’),
(‘row2valueForColumnName1’, ‘row2valueForColumnName2’, row2valueForColumnName3, ‘row2valueForColumnName4’),
(‘row3valueForColumnName1’, ‘row3valueForColumnName2’, row3valueForColumnName3, ‘row3valueForColumnName4’)
returning *;

for values, text values go into single quotes; numbers do not

each tuple would be separated by a comma

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

How do you get back the row being inserted into a table without a separate select statement?

A

returning clause

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

How do you update rows in a database table?

A

update “tableName”
set “columnName” = value (not in quotes if this is a number)
where “idName” = idNumber(this is a number btw im);

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

Why is it important to include a where clause in your update statements?

A

Because then it would update every row in the table! VERY BAD thats not what we want

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

How do you delete rows from a database table?

A

delete from “tableName”

where “columnName” = value;

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

How do you accidentally delete all rows from a table?

A

delete from “tableName”;

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

What are some examples of aggregate functions?

A

average(), max(), min(), sum(), count()

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

What is the purpose of a group by clause?

A

to separate the rows into their own groups and perform aggregate functions

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