PostgreSQL Flashcards
What is PostgreSQL and what are some alternative relational databases?
- PostgreSQL is a powerful, free, open source Relational Database Management System. (relational databases use some variation of the SQL language… opposite of NoSQL)
- alternatives: mySQL, SQLite, Oracle
What are some advantages of learning a relational database?
- they are ubiquitous
- they support good guarantees about data integrity
- they 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” data and not worry about data being “half written”
What is one way to see if PostgreSQL is running?
sudo service postgresql status
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 in a database?
- a list of rows each having the same set of attributes (columns)
- a sort of spreadsheet where each row is a record in that spreadsheet
What are rows and columns in a database?
- -columns are a set of data values of a particular type. they contain the column name, data type, or any other attributes for the column
- rows, aka “tuples”, represent the data item in a table
What is SQL and how is it different from languages like JavaScript?
-where JavaScript is imperative in that you tell JavaScript what to do, SQL is declarative. you just describe the results you want, and SQL will come up with its own plan for getting those results (like html/css)
How do you retrieve specific columns from a database table?
-“select” clause
select “column-name-1”,
“column-name-2”
from “database-table-name”
How do you filter rows based on some specific criteria?
-“where” clause
select “xyz-column”
from “xyz-table-name”
where “xyz-column-2” = “abc”
What are four comparison operators that can be used in a where clause?
, =, and !=
How do you limit the number of rows returned in a result set?
-“limit” clause (comes last)
select *
from “xyz-table-name”
limit 10
How do you retrieve all columns from a database table?
select *
How do you control the sort order of a result set?
-“order by” clause; asc/desc
How do you add a row to a SQL table?
insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’);
What is a tuple?
a list of values (aka a row in a database table)