PostgreSQL Flashcards
What is PostgreSQL and what are some alternative relational databases?
PostgreSQL is a relational database
Alternatives: Redis, MongoDB, Neo4j
What are some advantages of learning a relational database?
SQL (structured query language) language/jargon is used in many relational databases, so skills are transferable
What is one way to see if PostgreSQL is running?
Sudo service postgresql status
Sudo elevates you to administrative privileges
Echo $(whoami) shows the current user name
**usually asks for password
Service
Managing a background process
Postgresql status
Status tells you if it’s running or not
Start will start the program
Stop will stop the program
What is a database schema?
Collection of tables
Rules of how the data can be stored
The structure of the database
If there’s no schema, usually in non-relational databases
What is a table?
List of rows with the same of attributes(columns)
What is a row?
Collection of attributes for a single row in a table
What is SQL and how is it different from languages like JavaScript?
“Structured Query Language” is a declarative programming language, where programmers describe the results they want and the programming environment comes up with its own plan for getting said results. (like HTML and CSS)
JavaScript is imperative programming language and we have to tell it exactly what to do, step by step
How do you retrieve specific columns from a database table?
Select “insert-column-name-here” (multiple, separated by commas)
From “insert-database-table-name-here”
How do you filter rows based on some specific criteria?
Specify value from column
Where “insert-column-name” = ‘insert-value-name’;
What are the benefits of formatting your SQL?
Easier readability
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 how many results you want
Limit [insert-number]
How do you retrieve all columns from a database table?
Use * [asterisk for all]
Select *
How do you control the sort order of a result set?
Order by “insert-name-of-what-to-order-by” desc
Ascending by default
Desc for greatest to least
How do you add a row to a SQL table?
Insert keyword
Insert into “table-data-name” (“column-name”, “more-column-names”)
Values (‘value of first column-name’, ‘value of second column-name’)
Returning * [optional, but shows immediately what you inserted]