PostgreSQL Flashcards
What is PostgreSQL and what are some alternative relational databases?
PostgreSQL is a free open source relational database management system
Alternative relational databases include: MySQL (also free), SQL Server by Microsoft, and Oracle by Oracle Corporation.
What are some advantages of learning a relational database?
- If you are storing related data, then a relational database is a good choice.
- Relational databases support good guarantees about data integrity.
- Relational databases are arguably the most widely used kind of database.
- And knowing the SQL language is a very portable skill given that there are so many relational databases driven by almost the same language (SQL)
What is one way to see if PostgreSQL is running?
- Use the terminal command sudo service postgresql status.
- Check use the terminal top command to see if postgres is running
What is a database schema?
A collection of tables is called a schema. A schema defines how the data in a relational database should be organized.
What is a table?
A table is a set of relational data. A table is a list of rows, the rows all have the same attributes
What is a row?
A row is a single instance of a record in a spreadsheet/table
What is SQL and how is it different from languages like JavaScript?
Structured Query Language (SQL) is the primary way of interacting with relational databases. It is a powerful way of retrieving, creating, and manipulating data in a relational database.
JavaScript is an imperative programming language, where you basically tell the JavaScript runtime what to do and how to do it.
SQL is a declarative programming language where programmers describe the results they want and the programming environment comes up with its own plan for getting those results. (like html & css)
How do you retrieve specific columns from a database table?
Start with the select keyword.
The select keyword is followed by a comma-separated list of column names, each surrounded by “double quotes”.
e.g: select “firstName”,
“lastName”
How do you filter rows based on some specific criteria?
Use the where keyword followed by the column you want to filter by in “double quotes”, followed by an optional comparison operator, followed by an optional value of that column that you want to see in ‘single quotes’ (if the value is a number, do not use quotes at all.)
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?
Use the limit keyword followed by the number of rows you want to see.
e.g: limit 10;
How do you retrieve all columns from a database table?
Use the select keyword followed by *
e.g: select *
How do you control the sort order of a result set?
Use the order by keyword followed by the column you want to order by in “double quotes.” order will be in ascending order by default - add desc keyword after “specified column” to sort in descending order.
How do you control the sort order of a result set?
Use the order by keyword followed by the column you want to order by in “double quotes.” order will be in ascending order by default - add desc keyword after “specified column” to sort in descending order.
How do you add a row to a SQL table?
insert into “table” (“columnName”, “columnName”,… )
values (‘value’, ‘value’, ‘value’, …);
values are in the same order as the columns they belong to