0
0
SQLquery~5 mins

Dropping and altering views in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the SQL command DROP VIEW do?
It removes an existing view from the database permanently. After dropping, the view no longer exists and cannot be queried.
Click to reveal answer
beginner
How do you change the structure or definition of an existing view in SQL?
You use the CREATE OR REPLACE VIEW statement with the new definition. This updates the view without dropping it first.
Click to reveal answer
intermediate
True or False: You can use ALTER VIEW to modify a view's SELECT statement in all SQL databases.
False. Not all SQL databases support ALTER VIEW. Many require dropping and recreating the view or using CREATE OR REPLACE VIEW.
Click to reveal answer
beginner
What happens if you try to drop a view that does not exist using DROP VIEW view_name;?
The database will return an error unless you use DROP VIEW IF EXISTS view_name; which avoids errors if the view is missing.
Click to reveal answer
intermediate
Why might you prefer CREATE OR REPLACE VIEW over dropping and recreating a view?
Because it keeps permissions and dependencies intact and avoids errors if the view is referenced elsewhere in the database.
Click to reveal answer
Which SQL command removes a view permanently?
ADROP VIEW view_name;
BALTER VIEW view_name;
CCREATE VIEW view_name;
DRENAME VIEW view_name;
How do you update the SELECT query of an existing view without dropping it first?
AALTER VIEW view_name AS SELECT ...;
BDROP VIEW view_name; CREATE VIEW view_name AS SELECT ...;
CCREATE OR REPLACE VIEW view_name AS SELECT ...;
DUPDATE VIEW view_name SET SELECT ...;
What does DROP VIEW IF EXISTS view_name; do?
ADrops the view only if it exists, avoiding errors if it doesn't.
BCreates the view if it does not exist.
CRenames the view if it exists.
DAlters the view if it exists.
Which statement is true about ALTER VIEW?
AAll SQL databases support <code>ALTER VIEW</code> to change view definitions.
BSome databases support <code>ALTER VIEW</code>, but many require <code>CREATE OR REPLACE VIEW</code>.
CNo SQL database supports <code>ALTER VIEW</code>.
D<code>ALTER VIEW</code> deletes the view.
Why is CREATE OR REPLACE VIEW often preferred over dropping and recreating a view?
AIt renames the view.
BIt automatically backs up the view.
CIt deletes all data in the view.
DIt keeps permissions and dependencies intact.
Explain how to safely update the definition of an existing view in SQL.
Think about commands that replace without deleting.
You got /3 concepts.
    Describe what happens when you drop a view and why you might want to use IF EXISTS.
    Consider error handling when the view might not be there.
    You got /3 concepts.