0
0
SQLquery~20 mins

Views for security and abstraction in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
View Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of a simple view query
Given the table Employees with columns id, name, salary, and a view HighEarners defined as CREATE VIEW HighEarners AS SELECT id, name FROM Employees WHERE salary > 70000;, what will be the output of SELECT * FROM HighEarners; if the table contains:

id | name | salary
1 | Alice | 80000
2 | Bob | 60000
3 | Carol | 90000
SQL
CREATE VIEW HighEarners AS SELECT id, name FROM Employees WHERE salary > 70000;
SELECT * FROM HighEarners;
A[{"id":1,"name":"Alice"},{"id":3,"name":"Carol"}]
B[]
C[{"id":2,"name":"Bob"}]
D[{"id":1,"name":"Alice"},{"id":2,"name":"Bob"},{"id":3,"name":"Carol"}]
Attempts:
2 left
💡 Hint
Remember the view filters employees with salary greater than 70000.
🧠 Conceptual
intermediate
1:30remaining
Purpose of using views for security
Why are views often used to improve security in databases?
AThey automatically encrypt data stored in the database.
BThey allow restricting user access to specific columns or rows without giving full table access.
CThey speed up query execution by storing data physically.
DThey prevent users from running any queries on the database.
Attempts:
2 left
💡 Hint
Think about how views can limit what data users see.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in view creation
Which option contains a syntax error when creating a view that shows only active customers from a Customers table with a boolean active column?
ACREATE VIEW ActiveCustomers AS SELECT * FROM Customers WHERE active == TRUE;
BCREATE VIEW ActiveCustomers AS SELECT * FROM Customers WHERE active = TRUE;
CCREATE VIEW ActiveCustomers AS SELECT * FROM Customers WHERE active IS TRUE;
DCREATE VIEW ActiveCustomers AS SELECT * FROM Customers WHERE active = 1;
Attempts:
2 left
💡 Hint
Check the comparison operator used in SQL.
optimization
advanced
2:30remaining
Optimizing view performance with indexes
You have a view RecentOrders defined as SELECT * FROM Orders WHERE order_date > CURRENT_DATE - INTERVAL '30 days'. Which approach will best improve query performance when selecting from this view?
ADrop the view and query the <code>Orders</code> table without any indexes.
BCreate an index on the view <code>RecentOrders</code> directly.
CRewrite the view to select all orders without filtering.
DCreate an index on the <code>order_date</code> column in the <code>Orders</code> table.
Attempts:
2 left
💡 Hint
Think about how databases use indexes to speed up filtering.
🔧 Debug
expert
3:00remaining
Why does this view cause an error on update?
Consider the view CREATE VIEW EmployeeNames AS SELECT id, name FROM Employees;. A user tries to run UPDATE EmployeeNames SET name = 'John' WHERE id = 5; but gets an error. Why?
AThe user does not have permission to update the Employees table.
BViews cannot be updated in any database system.
CThe view does not include all columns needed for an update, so it is not updatable.
DThe UPDATE statement syntax is incorrect for views.
Attempts:
2 left
💡 Hint
Think about what makes a view updatable.