SQL Flashcards
Why do we use SQL?
Flexible
Breaks into relational algebra
Very high level
What are the 3 types of SQL?
DDL - schema/constraint data
DML - insert/delete/modify data
DQL - find/join/aggregate data
How do we order SQL statements?
SELECT desired attributes
FROM one or more tables
WHERE condition about table rows
How do we do selection and projection in SQL?
Selection = WHERE Projection = SELECT all attributes of relation below
How do we rename columns in SQL?
AS
Renames attribute
How do we do computed attributes in SQL?
Use a calculation
Part of SELECT clause
How are NULL values used in SQL?
Tuples can be NULL
Any value compared with NULL = truth value unknown
How do we do 3 valued logic in SQL?
True = 1 Also = 0 Unknown = 0.5
How do we do multi-relation queries in SQL?
Combine data from multiple queries
List all in FROM clause
How do we do subqueries/nested queries in SQL?
SELECT-FROM-WHERE statements
How do we do HAVING statements in SQL?
HAVING
Follows GROUP BY clause
What are the 3 formal semantics of SQL?
Product of relations in FROM clause
Apply selection condition from WHERE clause
Project onto list of attributes/expressions in SELECT clause
How do we do explicit tuple variables in SQL?
Query needs to use 2 copies of same relation
Distinguish by putting relation name then tuple name in FROM clause
How do we do the EXISTS operator in SQL?
EXISTS
True if and only if is not empty
How do we do union/intersection/difference in SQL?
Default set semantics (duplicates deleted)