PostgreSQL/SQL Flashcards
What is PostgreSQL and what are some alternative relational databases?
PostgreSQL is a relational database. It is cited as the most advanced open-source and free relational database available. MySQL, SQL Server by Microsoft, and Oracle are some alternative relational databases.
What are some advantages of learning a relational database?
Most developers work with relational databases a little bit and many other relational databases work off the same SQL language.
What is one way to see if PostgreSQL is running?
sudo service postgresql status
What is a database schema?
A collection of tables. It defines how the data in a relational database should be organized.
What is a table?
Data stored in ‘relations’
What is a row?
A row is collection of attributes or a single record in a table
What is SQL and how is it different from languages like JavaScript?
SQL is a declarative language like HTML and CSS whereas JavaScript is an imperative language. With SQL, we describe the results we want and the environment figures out how to provide us with the result
How do you retrieve specific columns from a database table?
You use select followed by the column names in double quotes (separated by a comma if multiple)
How do you filter rows based on some specific criteria?
You can use where “row” and an assignment operator like =, <, >, or != and the value. If the value is a string use single quotes
What are the benefits of formatting your SQL?
It is more consistent and easier to read/understand
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 and the maximum number of rows you want returned
How do you retrieve all columns from a database table?
You can use the universal selector (*) after the select keyword
e.g. select *
How do you control the sort order of a result set?
A result set returns in ascending order by default. If you want it to be returned in descending order you would use the order by keywords, the column name in double quotes, followed by the desc keyword
e.g. order by “price” desc
How do you add a row to a SQL table?
insert into