sql Flashcards

1
Q

What is SQL and how is it different from languages like JavaScript?

A

SQL is a declarative programming language where programmers describe what they want to see and the environment comes up with the necessary processes to provide something accurate

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

How do you retrieve specific columns from a database table?

A

select “columnname”

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

How do you filter rows based on some specific criteria?

A

use where “columnname” = ‘value’

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

What are the benefits of formatting your SQL?

A

reusability and organization

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

What are four comparison operators that can be used in a where clause?

A

=, , !=

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

How do you limit the number of rows returned in a result set?

A

limit x where x is an integer

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

How do you retrieve all columns from a database table?

A

select *

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

How do you control the sort order of a result set?

A

order by

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

How do you add a row to a SQL table?

A

use insert into “table” (“columnname1”, “columnname2”, “columnnameX”)
values (‘value1’, ‘value2’, ‘valueX’);

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

What is a tuple?

A

a list of values

ex: values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’)

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

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

A

add multiple tuples separated by a comma

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

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

A

returning * to receive everything or returning “columnnameX” to receive certain columns

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

How do you update rows in a database table?

A

update “table”

set “columnname” = ‘value’;

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

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

A

otherwise, every row gets updated

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

How do you delete rows from a database table?

A

delete from “table”

where “columnname” = ‘value’;

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

How do you accidentally delete all rows from a table?

A

no where statement to specify what you are deleting

17
Q

What is a foreign key?

A

A foreign key refers to the values that connect different tables of data together

18
Q

How do you join two SQL tables?

A

join “table” using (“foreignkey”);

19
Q

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

A

as “tempName”

20
Q

What are some examples of aggregate functions?

A

sum() count() avg() max() min()

21
Q

What is the purpose of a group by clause?

A

it organizes the data into categories