SQL insert, update, delete, join and aggregates Flashcards

1
Q

How do you add a row to a SQL table?

A

insert into “name of table to insert to” (“column names separated by commas”)
values (’text values wrapped in single quotes’, number values with literal numbers);

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 atuple.

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

Data rows can be batch inserted into a database table by specifying more than onetupleof values, separated by commas

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

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

A

Keyword returning *;

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 “table name”

set “attribute column name” = ‘value’ and no single quotes if it’s a number value

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

You don’t want to update every row to have the same value (unless that is what you intend to do)

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

Keyword delete from and table name and followed a where clause!!!! If not, the entire table will be deleted

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

By not specifying where

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

What is a foreign key?

A

Is a set of attributes in a table that refers to the primary key of another table. Theforeign keylinks these two tables.

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

How do you join two SQL tables?

A

Use the join keyword followed by “tableName” followed by using keyword followed by (“foreign key”);

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

How do you temporarily rename columns or tables in a SQL statement?

A

Use as (e.g table_name as alias_name)

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

What are some examples of aggregate functions?

A

max(), avg(), count(), min(),sum(), andevery()

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

What is the purpose of a group by clause?

A

Groups only certain rows that the user chooses to perform an action on – apply aggregate functions only on selected rows

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