SQL Flashcards

1
Q

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

A

SQL is way of interacting with relational databases and is different from JavaScript because it is a declarative programming languages. You also don’t really tell the computers what to do.

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

using select “column name or attributes”

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

you use where clause “column name” = the ‘row name’

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

It makes your code easier to read and decipher

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

with limit operator

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

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

A

order by “column name” - by default it is ascending order and can make it descending by desc operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
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
9
Q

How do you add a row to a SQL table?

A

using insert keyword with what columns and values you want to insert

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

What is a tuple?

A

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

you specify 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

using 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

use update statement with “file name” and set clause

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 statement?

A

Without the where clause, set value will be updated to all rows

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

Use delete statement with where clause

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

delete from “file name”

17
Q

What is a foreign key?

A

foreign key links one table to another with same attributes

18
Q

How do you join two SQL tables?

A

using join clause with using keyword and attribute you want to join together

19
Q

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

A

using as keyword

20
Q

What are some examples of aggregate functions?

A

sum(), min(), every(), avg()

21
Q

What is the purpose of a group by clause?

A

To separate rows into groups and perform aggregate functions on those groups of rows