POSTGRESQL Flashcards
What is PostgreSQL and what are some alternative relational databases?
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
What are some advantages of learning a relational database?
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
What is one way to see if PostgreSQL is running?
Top
What is a database schema?
A collection of tables that defines how the data in a relational database should be organized.
What is a table?
A table is a list of rows that stores database with each having the same set of attributes.
What is a row?
Holds all of the attributes for a single record of data
What is SQL and how is it different from languages like JavaScript?
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 do you retrieve specific columns from a database table?
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 do you filter rows based on some specific criteria?
Where “ ” = ‘ ’
EX:
select *
from “actors”
where “actorId” = 40;
What are the benefits of formatting your SQL?
Legibility, easier to read
What are four comparison operators that can be used in a where clause?
, =, !=
How do you limit the number of rows returned in a result set?
Limit
Ex: limit 10
OR
limit 10 Offset 6
(Offset skips the first 6 and then grabs the next 5)
How do you retrieve all columns from a database table?
*
Ex:
select *
How do you control the sort order of a result set?
order by “ “ desc/asc
If you dont have order by, default is asc
How do you add a row to a SQL table?
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’);