sql-insert Flashcards

1
Q

How do you add a row to a SQL table?

A

Using the “insert into” clause followed by the table name surrounded in double quotes, followed by the column name(s) surrounded by double quotes. Then on the next line, use the “values” keyword, followed by the values you want to add in single quotes (in the order of the column names specified on the previous line). Then on the next line, use the “returning” keyword followed by an asterisk if you want to return everything.

insert into (name of table in double quotes) (names of column in double quotes separated by commas and everything surrounded by parentheses)
values (names of values in single quotes separated by commas and everything surrounded by parentheses)
returning *;

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

What is a tuple?

A

A list of values

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

In the line with the “values” keyword, enter the values you want for each row in its own set of parentheses, with each set of parentheses having its own line and separated by commas.

insert into (name of table in double quotes) (names of column in double quotes separated by commas)
values (names of values in single quotes separated by commas),
(names of values in single quotes separated by commas)
returning *;

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

Use the “returning” keyword

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