SQL Flashcards
What’s the difference between CREATE VIEW
and CREATE OR REPLACE VIEW
?
The latter drops a view with the name specified in the statement if it already exists, and creates it again, saving you from running into errors, and saving you time by not needing to drop the view before
Which are the 4 types of JOIN
s?
Left, right, inner, and outer
What’s a self join?
A join that links a table to itself
Which are the 3 statements to join 2 tables?
ON
, WHERE
, and USING
Is cross join
the same as self join
?
No
When to use indexes?
Whenever you want to improve performance
Which are the 4 primitives data types?
Integer, string, boolean, and float
What’s the difference between CHAR
and VARCHAR
?
The former only accepts fixed-length values, whereas the latter accepts values regardless of their length
Which are the 3 main types of relationships?
One-to-one, one-to-many, and many-to-many
Can a primary key be nullable?
No
Can a boolean column be a primary key?
No
Which are the constraints you can set on a column?
Not null, unique, primary key, foreign key, check, and default
What does the rollback
statement mean within a transaction block?
If an error occurs within the block, it will rollback the data to its previous status, discarding any changes that might have occurred during its execution
How do you guarantee referencial data integrity?
Foreign keys and constraints
What would you use a stored procedure for?
To improve performance for a complex query, as it would compile once, and run based on an execution plan that is created the first time the procedure is ran