SQL Flashcards
Why SQL?
High-level language that specifies “what” rather than “how” avoiding data manipulation details; lets DBMS optimize and execute “best way”
What is the Basic SQL Query?
SELECT [Distinct] target-list FROM relation-list WHERE qualification
What does FROM specify?
A list of relation names possibly with a range-variable
What does the SELECT specify?
The list of attributes of relations in relation-list
What does the WHERE specify?
The qualification or comparisons (Attribute op const/attribute) combined using AND, OR, NOT
What is DISTINCT and where is it placed?
Optional keyword indicating that the answer should not contain duplicates; its placed between SELECT and the target-list
What is the conceptual evaluation strategy of the basic SQL query?
- Compute the cross-product of the relation-list
- Discard resulting tuples if they fail qualifications
- Delete attributes not in the target-list
- If distinct is specified, eliminate duplicate rows
What is a Range variable and when are they Variables needed?
Ex: From Relations R;
needed only if the same relation appears twice in the FROM caluse
What is LIKE keyword used for and where is it used?
Used for string matching in the WHERE clause.
Ex: WHERE s.name LIKE ‘B-%B’
In conjunction with LIKE, what does _ mean
Any one character
In conjunction with LIKE, what does % mean
0 or more characters
What are two ways to name fields in a result?
Using AS and =
Ex: SELECT age1=S.age-5, 2*S.age AS age2
Does SELECT-FROM-WHERE use bag or set semantics? Why?
Bag because it is easier to avoid eliminating duplicates.
Does union, intersection, and difference use bag or set semantics? Why?
Set because it’s already sorted so it’s easy to eliminate duplicates.
How do you force the result to be a set?
SELECT DISTINCT
How do you force the result to be a bag?
ALL Keyword (Ex: UNION ALL)
What is a nested Query?
A feature where WHERE, FROM, or HAVING clauses can contain an SQL query?