SQL Flashcards

1
Q

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

A

SQL is a declarative programming language. In declarative languages, programmers describe the results they want and the programming environment comes up with its own plan for getting those results.

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 “columns” from table

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

select “columns” from table where “rows”=’content’

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

easily readable

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

=, < , >, !=

<>(not equal in postgresql)

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 clause and specify the number of rows

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 * from table

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

select * from table order by “” desc

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

insert into table (columns)
values (values)
returning *;

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

What is a tuple?

A

a tuple is a finite ordered list of elements. (list of values)

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

Data rows can be batch inserted into a database table by specifying more than one tuple of values, separated by commas.

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 *;

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 “column”

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

to only target specific rows in the table

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 “column”

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

if you don’t target specific rows by including the ‘where’ clause

17
Q

what is a foreign key?

A

A foreign key is a column or group of columns in a relational database table that provides a link between data in two tables.

same column value

18
Q

How do you join two SQL tables?

A

join table using column

19
Q

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

A

select columns as new-name (aliasing with the as keyword)

20
Q

What are some examples of aggregate functions?

A

count, sum, max, min

21
Q

What is the purpose of a group by clause?

A

want to separate rows into groups and perform aggregate functions on those groups of rows. This is done with a group by clause.