PostgreSQL & SQL Flashcards
What is PostgreSQL and what are some alternative relational databases?
Relational Database Management System (RDBMS).
MySQL, SQL Server by Microsoft, and Oracle by Oracle Corporation.
What are some advantages of learning a relational database?
Good for storing related data.
They support good guarantees about data integrity. They can store and modify data in a way that makes data corruption as unlikely as possible. This means that 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; defines how the data in a relational database should be organized
What is a table?
Stored data in relations; a list of rows each having the same set of attributes; Attributes are commonly referred to as columns.
sort of spreadsheet
What is a row?
Data entries with the same set of attributes.
What is SQL and how is it different from languages like JavaScript?
Structured Query Language (SQL); primary way of interacting with relational databases. It is a powerful way of retrieving, creating, and manipulating data in a relational database;
SQL is a declarative programming language, 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?
select “column-name”,
“column-name”
from “table-name”;
How do you filter rows based on some specific criteria?
where “column-name” = ‘column-value’;
string using single quotes ‘column-value’; number just use number
What are the benefits of formatting your SQL?
for consistent style and therefore readability.
What are four comparison operators that can be used in a ‘where’ clause?
!=, =, ‘>’, ‘less-than’
How do you limit the number of rows returned in a result set?
limit ‘number’
How do you retrieve all columns from a database table?
select *
How do you control the sort order of a result set?
order by “price” desc
How do you add a row to a SQL table?
insert into “table-name” (“column-name”)