SQL Flashcards

1
Q

What is SQL(Structure Query Language) and how is it different from languages like JavaScript?

A

JavaScript is used for front end web development while SQL is used for performing operations on database. JavaScript is a procedural ,scripting language. SQL is a declarative language.

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

To select a single column, we specify the column name between SELECT and FROM as follows:

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

where

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

Helps us to make the queries more readable and easy to understand.
When the queries are formatted and laid out with proper spacing it comes easy to find the errors in the query and fix the error.
Formatted queries are easy to be passed on to the fellow developers.
Helps in increasing the efficiency of the database transaction system.
Makes it easy to scale and deploy the database system.

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 limit

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

To retrieve all columns, use the wild card * (an asterisk)

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

insert into “products” (“name”, “description”, “price”, “category”)
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
10
Q

What is a tuple?

A

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

insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’),
(‘Tater Mitts’, ‘Scrub some taters!’, 6, ‘cooking’)
returning *;

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

set “price” = 100;

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 target specific 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

delete from “products”
where “productId” = 24
returning *;

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

What is a foreign key?

A

a column (or combination of columns) in a table whose values must match values of a column in some other table

17
Q

How do you join two SQL tables?

A

join

18
Q

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

A

“as”

19
Q

What are some examples of aggregate functions?

A

min(), sum(), every()
it works like .redue().
takes a bunch of values to a single value

20
Q

What is the purpose of a group by clause?

A

get the summary data based on one or more groups.