SQL MYSTERY TUTORIAL Flashcards
What does SQL stand for and what does it do?
Structured Query Language
It is a way to interact w/ relational databases and tables that allow humans to glean specific, meaningful information
What is a relational database?
Best known type of database, but No single definition for word database
Can have varying amount of structure imposed on data
“Relational” part comes w/ specific rules about how to connect data btw different tables
What are relational databases made of? Describe what they look like.
Made of tables, like spreadsheets
Each column in table has name and data type (text, number)
Each row in the table is a specific instance of what the table is about
What does ERD stand for? What is an ERD?
Entity relationship diagram
Visual representation of the relationships among all relevant tables w/in a database
Describe the ERD
Diagram that shows each table, comprised of a name, column names, & data types
Describe the gold key, blue arrow and gray arrows on ERD
*Gold key indicates the column is the primary key of the corresponding table
*Blue arrow: indicates the column is the foreign key of the corresponding table
*Gray arrow: if two tables are related, the matching columns, i.e., the common identifiers of the two tables, are connected by gray arrow
What is a primary key?
A unique identifier for each ROW in a table
What is a foreign key?
Used for reference data in one table to those in another table
What is a query?
Statements constructed to get data from database
Describe trying a query against the database
- For each boxes below, click the “run” to “execute” the query in the box
- You can edit the queries on the page to explore (not case sensitive, but conventional to capitalize for readability; you can use new lines and white spaces to format command for readability).
- Most database systems require to end query in semicolon (;)
- You can change subject of FROM to any other table from the ERD to learn how many rows that table has
Part 2 of Describing query against database
What do we know about the subject/if you want data for each row in a table, use what?
Use * after ‘SELECT’ Rather than seeing all of them, limit results to first 10
SELECT * FROM person LIMIT 10;
Part 3 of describing a query against a database
What are possible values for a column?
When working w/ data, always see if you can find documentation that explains the _____. Is this always available?
What does the DISTINCT keyword do?
explains the database structure (like the ERD) and valid values. But not always available
DISTINCT keyword can give you a quick look at which values are in the database.
After you run it, delete the word DISTINCT and run it again. (after you try that click “reset” and run one more time before continuing)
What elements does a SQL query have? (6 main ones)
*SQL keywords (ex- SELECT, FROM)
*Column names (like name column)
*Table names (ex- person table)
*Wildcard characters (ex- %)
*Functions
*Specific filtering criteria
What are SQL keywords used for?
*Used to specify actions in your queries
*not case sensitive, but use all caps to easily identify
What are some frequently used SQL keywords and what are they used for?
SELECT- allows grabbing of data from specific columns from the database
FROM- allows us to specify which table(s) we care about
WHERE- clause in a query that is used to filter results by specific criteria