PostgreSQL/SQL Flashcards
What is PostgreSQL and what are some alternative relational databases?
Open source relational database server
Other databases: SQLite, SQL Server, Oracle SQL
What are some advantages of learning a relational database?
Great if you are storing related data. Less likelihood of data corruption. Most importantly: you will use it as a developer.
What is one way to see if PostgreSQL is running?
sudo service postgresql status
What is a database schema?
Dictates how data should be organized
What is a table?
Organized rows that have the same set of attributes. Overall, a place where data can be stored
What is a row?
One record in a table
What is SQL and how is it different from languages like JavaScript?
Its a declarative language meaning you tell what you want and the language will interpret it. On the other hand, JS is imperative meaning you have to tell it exactly what you want it to do.
How do you retrieve specific columns from a database table?
select “column”
from “table”;
How do you filter rows based on some specific criteria?
where clause “column” = ‘data’
What are the benefits of formatting your SQL?
SQL can get very complex. Structuring it will make it easier to read.
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?
*
How do you control the sort order of a result set?
order by “column” desc/asc
How do you add a row to a SQL table?
insert into “table” (“column”, “column”)
What is a tuple?
Specific ordered list with paranthesis
How do you add multiple rows to a SQL table at once?
values (‘data’, ‘data’) separated by comma
How do you get back the row being inserted into a table without a separate select statement?
returning clause
How do you update rows in a database table?
update “table”
set “column” = ‘data’
where “column” = ‘data’
Why is it important to include a where clause in your update statements?
So you don’t update all the rows
How do you delete rows from a database table?
delete from “table”
where “column” = ‘data’
How do you accidentally delete all rows from a table?
delete from “table” with no other clauses
What is a foreign key?
Columns that refer to another column in a different table. Data should match.
How do you join two SQL tables?
join “table” using (“column”)