POSTGRESQL Flashcards

1
Q

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is a powerful, free, open source Relational Database Management System (RDBMS). It is often cited as the most advanced open source database of its kind and is well-liked by the developer community for its robust feature set, standards compliance, and reliability.

SQLite, Oracle

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
Many problem domains can be modeled well using a relational database.
Relational databases are arguably 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

Top

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 that defines how the data in a relational database should be organized.

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

What is a table?

A

A table is a list of rows that stores database with each having the same set of attributes.

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

What is a row?

A

Holds all of the attributes for a single record of data

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 (Structured Query Language) is a domain-specific language used in programming and designed for managing data held in a relational database management system (RDBMS

In JavaScript, you tell the computer how to do its job. Imperative programming.

In SQL, you declare the computer what you want as an output. Declarative programming

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

Select “ ”

EXAMPLE: 
select "actorId",
  "firstName",
  "lastName"
  from "actors";

The query starts with the select keyword.
The select keyword is followed by a comma-separated list of column names, each surrounded by “ double quotes.
The column names are followed by a from clause specifying which table to retrieve the data from.
The query must end in a ; semicolon.
SQL keywords such as select and from are not case-sensitive.
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
9
Q

How do you filter rows based on some specific criteria?

A

Where “ ” = ‘ ’

EX:
select *
from “actors”
where “actorId” = 40;

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

Legibility, easier to read

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

Ex: limit 10

OR

limit 10 Offset 6

(Offset skips the first 6 and then grabs the next 5)

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

*

Ex:
select *

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 “ “ desc/asc

If you dont have order by, default is asc

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

First, the table, which you want to insert a new row, in the INSERT INTO clause.

Second, a comma-separated list of columns in the table surrounded by parentheses.

Third, a comma-separated list of values surrounded by parentheses in the VALUES clause.

Ex:
INSERT INTO shippers(companyName, phone)
VALUES (‘Alliance Shippers’, ‘1-800-222-0451’);

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

17
Q

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

A

Data rows can be batch inserted into a database table by specifying more than one tuple of values, separated by commas. Below we are inserting two new rows into the “products” table.

Ex: 
INSERT INTO table_name (column_list)
VALUES
    (value_list_1),
    (value_list_2),
    ...
    (value_list_n);
18
Q

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

A

Returning *

Returning “name”