sql Flashcards

1
Q

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

A

it is a declaritive language. So instead of telling the language to “find” something. You can tell it what to find, and it will do it itself

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

you use:

select (name of column)

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 can use the where clause.
you can get a subset of all rows in a table depending on the criteria

where “category” = ‘cleaning’

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

The readability of your data

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

using the limit command

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

by using order by with the column selected.

it will be ascending by default, but can be descending if stated otherwise

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 the insert clause with the designating table

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 group of values that is encased in a parenthsis

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

within the values clause. you would add X-amount of parenthesis seperated by commas. each new tuple will be a new row.

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

use the returning clause followed with a *. This will return the row that you have created. If you want specific values, you would replace the * with the list column items

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

you use the update clause followed with the update and where

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

IT IS IMPORTANT TO USE the WHERE clause to make sure that you are not updating EVERYTHING

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 the delete from clause folowered by a 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

where you forget to use a where clause with the delete

17
Q

What is a foreign key?

A

it is a value/column that specifically refers to values in another table.

18
Q

How do you join two SQL tables?

A
we use the `join` clause
Designating the table and how they are connect.
`select *
from "products
join "suppliers" using ("supplierId")`
19
Q

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

A

you use the as clause:

select “products”.”name as “product…

this will change the column “name” in the table “products” to the name “product”