PostgreSQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

pronounced “Post Gress Queue El”, PostgreSQL is a powerful, free, open source Relational Database Management System (RDBMS).
Alternatives - MySQL, SQL Server by MIcrosoft, and Oracle by Oracle Corporation.

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

They can store and modify data in a way that makes data corruption as unlikely as possible.
You can store related data.
Relational Databases are the most widely used kind of database.

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

use the command ‘ sudo service postgresql status ‘.

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

psql

A

the command to acces PostgreSQL in the terminal.

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

pgweb

A

is just a graphical user interface for the PostgreSQL database.

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

What is a database schema?

A

A collection of tables , and defines how the data in a relational database should be organized.
defines the structure of a database.

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

What is a table?

A

A table is a list of rows each having the same set of attributes.
Ex - all students in a “students” table could have “firstName”, “lastName”, and “dateOfBirth” attributes.
Attributes are commonly referred to as tables.

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

What is a row?

A

each row in a table is a record of data
a row is a data record within a table.
holds data that correlates to the attribute or column .
the stored or collected data.

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

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

A

SQL is a declarative programming language which means you describe the results you want and then its up to the programming environment to come up with a plan for getting the results, whereas JavaScript is imperative which means you tell the program / runtime what to do and how to do it.

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

How do you retrieve specific columns from a database table?

A

use the select keyword followed by a comma-separated list of column names, each surrounded by “ double quotes.
select column
from table name;

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

How do you filter rows based on some specific criteria?

A

use the where clause, which uses operators.

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

What are the benefits of formatting your SQL?

A

SQL does not have to be indented, but you should do it anyway for consistent style and therefore readability.

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

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

A

The limit clause includes a literal integer number with no quotes to specify the maximum number of rows that should be returned.

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

How do you retrieve all columns from a database table?

A

use the * (asterick) after the select keyword.

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

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

A

Order by clause
The default sort order of the results is ascending order, but you can switch it by adding descending keyword in the order by clause.

17
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’);
use insert keyword, then the table to insert into is specified in “ double quotes.

18
Q

What is a tuple?

A

In SQL, a list of values is referred to as a tuple.

values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’);

19
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 *;
insert however many tuples of values you specify and seperate them by commas.

20
Q

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

A

use the returning clause, followed by an asterick and semicolon.
returning *;

21
Q

How do you update rows in a database table?

A

use the Update keyword followed by the name of table in double quotes
underneath that use the Set keyword followed by what column you want to update, an equal signs then
whatever value you want to update it to.
update “products”
set “price” = 100;

22
Q

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

A

if you dont specify a where clause whatever you update the value to will change for every row for that column.

23
Q

How do you delete rows from a database table?

A

delete from “products”
where “productId” = 24
use the Delete From keyword followed by table name in double quotes, then the Where keyword followed by column name in double quotes, then an operator and a value.

24
Q

How do you accidentally delete all rows from a table?

A

delete from “tableName”;

Use the Delete From keyword then the table name in double quotes.

25
Q

What is a foreign key?

A

is a column with values that appears in different tables that can be linked to different tables.

26
Q

How do you join two SQL tables?

A

select “products”.”name” as “product”,
“suppliers”.”name” as “supplier”
from “products”
join “suppliers” using (“supplierId”);

select tableName followed by a period then the column name
from tableName
join tableName that has the foreign key using the foreign key.

27
Q

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

A

use the ‘ as ‘ keyword.

select “tableName”.”columnName” as “column1”.

from “tableName” as “table1”.

28
Q

What are some examples of aggregate functions?

A

MAX( ), AVG( ), COUNT( ), SUM( )

29
Q

What is the purpose of a group by clause?

A

The GROUP BY clause is used to group together those rows in a table that have the same values in all the columns listed.

A SQL command that is used to group rows that have the same values.