SQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is a free open-source relational database management system

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

What are some advantages of learning a relational database?

A

As a developer it is likely I will be working close to a database, so best to have knowledge of.

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

What is one way to see if PostgreSQL is running?

A

by running ‘sudo service postgresql status’ command

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

What is a database schema?

A

A collection of tables in a database.

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

What is a table?

A

A list of rows and columns that store data in relations.

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

What is a row?

A

A row is an entry in a table and every row contains the same set of attributes

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

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

A

SQL is a declarative language like html/css whereas other languages like JavaScript are imperative programing languages.
Declarative languages typically describe the results they want and the program environment gets the result in what ever way the program environment wants. Imperative languages tell an environment what to do and how to do it.

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

How do you retrieve specific columns from a database table?

A

By using the select keyword follow by one or more column name wrapped in double quotes.

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

How do you filter rows based on some specific criteria?

A

By using the where clause

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

What are the benefits of formatting your SQL?

A

For consistent style and readability

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

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

A

limit clause

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

How do you retrieve all columns from a database table?

A
  • (asterisk)symbol
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

order by (use desc for descending order)

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

How do you add a row to a SQL table?

A

By using an insert statement

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

What is a tuple?

A

A list of values in sql.

17
Q

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

A

A comma separated list of tuples after the values clause

18
Q

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

A

Use the returning with either an * for all columns or specify with a tuple of desired columns

19
Q

How do you update rows in a database table?

A

By using an update statement

20
Q

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

A

Because if you don’t specify with a where clause, every entry in the table will get updated.

21
Q

How do you delete rows from a database table?

A

By using a delete statement

22
Q

How do you accidentally delete all rows from a table?

A

By not specifying what to delete with the where clause

23
Q

What is a foreign key?

A

A foreign key is a column who’s purpose is to reference a column in a different table.

24
Q

How do you join two SQL tables?

A

Join clause

25
Q

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

A

By creating an Alias name with the as keyword