Postgres Flashcards
What is PostgreSQL and what are some alternative relational databases?
PostgreSQL is a free open-source relational database management system
PostgreSQL is a relational database system that is free and open source. Some alternatives are MySQL, SQL Server, and Oracle.
What are some advantages of learning a relational database?
They’re the most widely used type of database.
They support good guarantees about data integrity.
They can store and modify data in a way that makes corruption as unlikely as possible.
They are good for storing related data. They can store and modify data in a way that makes data corruption as unlikely as possible. Also, they are arguably the most widely used kind of database.
Simple Model. Flat
What is one way to see if PostgreSQL is running?
by running ‘sudo service postgresql status’ command
By having a 2nd terminal open and running the top command to monitor the open processes.
sudo service postgresql status / top
- Use the terminal command sudo service postgresql status.
- Check use the terminal top command to see if postgres is running
What is a database schema?
A collection of tables in a database.
What is a table?
A list of rows and columns that store data in relations.
What is a row?
A row is an entry in a table and every row contains the same set of attributes
A single instance of a record within a table.
What is SQL and how is it different from languages like JavaScript?
SQL is a declarative programming language. Instead of telling the code what to do, you describe the results you want.
How do you retrieve specific columns from a database table?
Start with the select keyword.
The select keyword is followed by a comma-separated list of column names, each surrounded by “double quotes”.
e.g: select “firstName”,
“lastName”
By using the select keyword follow by one or more column name wrapped in double quotes.
How do you filter rows based on some specific criteria?
By using the where clause
What are the benefits of formatting your SQL?
For consistent style and readability
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?
limit clause
How do you retrieve all columns from a database table?
asterisk
How do you control the sort order of a result set?
order by “column”; desc if you want it in descending order
Use the order by keyword followed by the column you want to order by in “double quotes.” order will be in ascending order by default - add desc keyword after “specified column” to sort in descending order.
How do you add a row to a SQL table?
insert statement insert into clause followed by the “table” then (column names separated by commas)
What is a tuple?
a list of values
How do you add multiple rows to a SQL table at once?
By using multiple tuples which are separated by commas but still follow the same order as the columns they belong to.
How do you get back the row being inserted into a table without a separate select statement?
using the returning keyword along with the star/asterisk
How do you update rows in a database table?
update clause followed by name of table. then the set clause followed by the column that needs updating followed by an equal operator then the value of the desired update
Why is it important to include a where clause in your update statements?
If a where clause is not used, the whole entire table is updated instead of just the targeted/desired data.
How do you delete rows from a database table?
delete from clause followed by the table
How do you accidentally delete all rows from a table?
By not specifying what to delete with the where clause
What is a foreign key?
a key used to link two tables together
A column that links one table to another
How do you join two SQL tables?
from clause followed by the table name and then the join clause followed by the table name as well and then the using keyword to specify the foreign key.
How do you temporarily rename columns or tables in a SQL statement?
By creating an Alias name with the as keyword
What are some examples of aggregate functions?
max(): Finds max number avg(): Finds average count(*): Counts number of rows min() sum() every() look into JSON aggregate functions
What is the purpose of a group by clause?
Separates rows into groups to perform aggregate functions.