Intermediate SQL Flashcards
(79 cards)
What is a join operation in SQL?
A join operation takes two relations and returns as a result another relation.
A join operation is a Cartesian product which requires that tuples in the two relations match under some condition.
What does the using clause do in SQL joins?
It specifies that values must match on specified attributes for a natural join.
This is a form of natural join.
What is the purpose of the on condition in SQL joins?
It allows a general predicate over the relations being joined.
The predicate is written like a where clause predicate except for the use of the keyword on.
What is an outer join in SQL?
An extension of the join operation that avoids loss of information by preserving tuples that would be lost in a join, creating tuples in the result containing null values.
What are the three forms of outer join?
- Left outer join
- Right outer join
- Full outer join
What does a left outer join do?
Preserves tuples only in the relation named before the left outer join operation.
What does a right outer join do?
Preserves tuples only in the relation named after the right outer join operation.
What is the full outer join?
It preserves tuples in both relations.
True or False: The right outer join is symmetric to the left outer join.
True
What is the primary purpose of integrity constraints in SQL?
To guard against accidental damage to the database by ensuring that authorized changes do not result in a loss of data consistency.
How can integrity constraints be added to an existing relation?
Using the command alter table table-name add constraint.
The constraint can be any constraint on the relation.
What does the not null specification do in SQL?
It prohibits the insertion of a null value for the specified attribute.
What does the unique constraint do in SQL?
It prevents the storage of repetition of data/values in the column but allows one NULL value.
What are candidate keys in SQL?
Attributes that are permitted to be null and can form a unique constraint.
Fill in the blank: An outer join adds tuples from one relation that does not match tuples in the other relation to the result of the join using _______.
null values
What is the difference between the on condition and where clause in outer joins?
The on condition is part of the outer join specification, while a where clause is not.
What is the role of the select statement in SQL?
To retrieve data from one or more tables in the database.
What is a natural join?
A type of join that automatically joins tables based on columns with the same name.
What do you achieve with a natural left outer join?
You retrieve all records from the left table and the matched records from the right table, with nulls for non-matching records.
What is the result of a full outer join?
It combines results from both left and right outer joins, showing all records from both tables.
What is a Cartesian product in SQL?
A result of combining all rows from two or more relations.
What does a unique constraint allow in a database?
Allows ONE NULL value.
More than one NULL value is also considered as repetition.
What is a candidate key?
Attributes A1, A2,…, Am that are permitted to be null.
What is the purpose of the CHECK constraint?
Specifies a predicate P that must be satisfied by every tuple in a relation.