Databases Flashcards
What is PostgreSQL and what are some alternative relational databases?
PostgreSQL is a powerful, free, open source Relational Database Management System (RDBMS).
Alternative relational databases: MySQL, SQL Server by Microsoft, Oracle by Oracle Corporation, SQLite
What are some advantages of learning a relational database?
- provide good guarantees about data integrity
- store and modify data in a way that makes data corruption as unlikely as possible.
- knowing SQL language
What is one way to see if PostgreSQL is running?
On terminal –
top command or
sudo service postgresql status
What is a database schema?
- a collection of tables.
- a schema defines how the data in a relational database should be organized.
What is a table?
- relational databases store data in relations.
- A table is a list of rows each having the same set of attributes
What is a row?
a row is a collection of fields that make up a record / values in a 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.
SQL is different from language like JS because it is a declarative programming language. In declarative languages, programmers describe the results they want and the programming environment comes up with its own plan for getting those results.
How do you retrieve specific columns from a database table?
you use the select statement and double quotes the column’s name. If you want multiple column, use a comma.
How do you filter rows based on some specific criteria?
where clause with the comparison operators
What are the benefits of formatting your SQL?
readability
What are four comparison operators that can be used in a where clause?
less than, greater than, equal to (=), not equal to ( != )
How do you limit the number of rows returned in a result set?
at the end of the code block and input “limit” followed by the number
How do you retrieve all columns from a database table?
select all of the columns in a table by replacing the list of column names with an * asterisk
ex select *
How do you control the sort order of a result set?
use the order by clause followed by the “name” of column and the keyword (desc for descending; ascending order is default).
Select statement notes:
- 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.
Example: select “name”, “price” from “products”;