w2d6-7 (SQL Intro) Flashcards
What is an RDMBS?
A relational database management system.
What do the rows and columns of a database table represent?
Each row represents a single entity, and each column denotes a specific piece of data for that entity.
What is a primary key, and what is the most common one in SQL?
A primary key is the unique identifier for a row of data, and the most typical one is ‘id’
In Rails, what does each table usually hold?
One type of resource (users, people, houses, posts, etc.)
What is a database schema, and what must you decide to implement it?
A database schema is a description of the organization of your database into tables and columns. You must decide what tables to have, what columns each table will have, and the data type of each column.
What is the difference between static and dynamic typing?
Static typing requires the data type of a variable be specified and immutable (SQL), whereas this is not a requirement in dynamic typing (Ruby)
What is a foreign key?
An entry in a table which points to a row (primary key) in a different table; used for associations between tables.
What is the convention for naming a foreign key?
[other_table_name_singularized]_id
What do the ‘SELECT’, ‘FROM’, and ‘WHERE’ clauses do?
SELECT takes a list of comma separated column names, FROM specifies a table to query, and WHERE specifies which rows to select depending on certain values of their columns (i.e. filters the data).
What are the 4 main data manipulation operations in SQL?
SELECT, INSERT, UPDATE, DELETE
What are the 3 operators to manipulate a database schema?
CREATE TABLE, ALTER TABLE, DROP TABLE
What does the ‘JOIN’ clause do?
It allows us to query across tables by associating a foreign key with a primary id.
What are the two components of the SQL language?
Data Definition Language (DDL), and Data Manipulation Language (DML)
Explain an INNER JOIN, FULL OUTER JOIN, and LEFT OUTER JOIN
An inner join produces a table consisting of rows where a certain column value matches.
A full outer join produces a set of all records where a certain column value matches. If there is no match, the record in the other table will contain null.
A left outer join does the samething, except all records are retained in the first table, and only matching records in the second table are retained.
Write the SQL query to join TableA and TableB on their name column value and then exclude all matching results.
SELECT * FROM TableA FULL OUTER JOIN TableB ON TableA.name = TableB.name WHERE TableA.id IS null OR TableB.id IS null