PostgreSQL Flashcards
What is PostgreSQL and what are some alternative relational databases?
- Relational database management system
- MySQL, Oracle, SQL Server by Microsoft
What are some advantages of learning a relational database?
Widely adapted database, so can be a highly transferrable language
What is one way to see if PostgreSQL is running?
sudo service postgresql status
What is a database schema?
- A collection of tables
- Defines how the data in a relational database should be organized
- Define a schema, and the database will make sure the data conforms to that schema
What is a table?
A table is a list of rows, each having the same set of attributes
What is a row?
- Records that are contained inside the table
- All the data that describes one item inside a table
What is SQL and how is it different from languages like JavaScript?
SQL is a declarative language, so we declare or query for data, and the SQL language finds a path to get us the results
JavaScript is imperative, we write functions by hand, so we tell JS how do handle the action as well.
How do you retrieve specific columns from a database table?
select “column”
If multiple columns, add comma then next column name.
How do you filter rows based on some specific criteria?
Using the where keyword with comparison operator between “column” and data (string, number, boolean)
where “column” = data
What are the benefits of formatting your SQL?
Data is easier to read and comprehend when organized
What are four comparison operators that can be used in awhereclause?
Comparison operators: =, !=, >,
How do you limit the number of rows returned in a result set?
- Using the limit keyword with a number
- limit 10
How do you retrieve all columns from a database table?
select *
How do you control the sort order of a result set?
- Ascending order is default
- order by “column” desc
How do you add a row to a SQL table?
Using insert into keyword followed by the “table”, and the column names in double quotes and parenthesis, separated by commas.
insert into actors (firstName, lastName)
values (‘Ken’ ,’Kieu’)