PostgreSQL Flashcards
What is PostgreSQL and what are some alternative relational databases?
- PostgreSQL is a powerful, free, open source Relational Database Management System (RDBMS)
- MySQL, SQL Server, ORACLE
What are some advantages of learning a relational database?
- widely used
- data integrity: can store and modify data in a way that makes data corruption as unlikely as possible
- developers can set up their database to reject “bad”/”half-written” data
What is one way to see if PostgreSQL is still running?
- top
- sudo service postgresql status
- try connecting to it
What is a database schema?
a collection of tables - defines how the data in a relational database should be organized
What is a table?
- relational databases store data in relations, commonly referred to as tables
- a list of rows each having the same set of attributes
What is a row?
a list of attributes that are all the same across each row
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.
- SQL 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. (Whereas imperative languages like JavaScript you basically tell the JavaScript runtime what to do and how to do it.)
How do you retrieve specific columns from a database table?
select “columnName”
How do you filter rows based on some specific criteria?
use a ‘where’ clause - an expression that has to evaluate to true or false - so can use < > = etc..
What are the benefits of formatting your SQL?
it’s easier to read - easier to debug - easier to remove stuff
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 a ‘limit’ clause
How do you retrieve all columns from a database table?
*
How do you control the sort order of a result set?
use ‘order by’ clause
How do you add a row to a SQL table?
- use the insert clause
- insert into “tableName” ( “colName”, “colName”, …)
values ( ‘colValue’ , ‘colValue’, …)
returning *;