SQL Flashcards
What is PostgreSQL and what are some alternative relational databases?
PostgreSQL is a free open-source relational database management system
What are some advantages of learning a relational database?
As a developer it is likely I will be working close to a database, so best to have knowledge of.
What is one way to see if PostgreSQL is running?
by running ‘sudo service postgresql status’ command
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
What is SQL and how is it different from languages like JavaScript?
SQL is a declarative language like html/css whereas other languages like JavaScript are imperative programing languages.
Declarative languages typically describe the results they want and the program environment gets the result in what ever way the program environment wants. Imperative languages tell an environment what to do and how to do it.
How do you retrieve specific columns from a database table?
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)symbol
How do you control the sort order of a result set?
order by (use desc for descending order)
How do you add a row to a SQL table?
By using an insert statement
What is a tuple?
A list of values in sql.
How do you add multiple rows to a SQL table at once?
A comma separated list of tuples after the values clause
How do you get back the row being inserted into a table without a separate select statement?
Use the returning with either an * for all columns or specify with a tuple of desired columns
How do you update rows in a database table?
By using an update statement
Why is it important to include a where clause in your update statements?
Because if you don’t specify with a where clause, every entry in the table will get updated.
How do you delete rows from a database table?
By using a delete statement
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 foreign key is a column who’s purpose is to reference a column in a different table.
How do you join two SQL tables?
Join clause
How do you temporarily rename columns or tables in a SQL statement?
By creating an Alias name with the as keyword