0
0
SQLquery~20 mins

CREATE VIEW syntax 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 CREATE VIEW query
Given the table Employees with columns id, name, and department, what will be the result of the following SQL query?

CREATE VIEW SalesEmployees AS SELECT id, name FROM Employees WHERE department = 'Sales';
SELECT * FROM SalesEmployees;
SQL
CREATE VIEW SalesEmployees AS SELECT id, name FROM Employees WHERE department = 'Sales';
SELECT * FROM SalesEmployees;
AReturns all employees with their id and name who work in the Sales department
BReturns all employees with their id, name, and department regardless of department
CReturns all employees with only their department column
DReturns an error because CREATE VIEW cannot be followed by SELECT
Attempts:
2 left
💡 Hint
Think about what the WHERE clause inside the view does.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in CREATE VIEW statement
Which option contains a syntax error in the CREATE VIEW statement?
ACREATE VIEW AS DeptView SELECT id, name FROM Employees;
BCREATE VIEW DeptView AS SELECT id, name FROM Employees WHERE department = 'HR';
CCREATE VIEW DeptView AS SELECT * FROM Employees;
DCREATE VIEW DeptView AS SELECT id, name FROM Employees WHERE department = 'IT';
Attempts:
2 left
💡 Hint
Check the order of keywords in the CREATE VIEW syntax.
optimization
advanced
2:00remaining
Choosing the best CREATE VIEW for performance
You want to create a view that shows only active customers from the Customers table. Which CREATE VIEW statement is most efficient if the Customers table has millions of rows and an index on the status column?
ACREATE VIEW ActiveCustomers AS SELECT id, name FROM Customers;
BCREATE VIEW ActiveCustomers AS SELECT * FROM Customers WHERE status = 'active';
CCREATE VIEW ActiveCustomers AS SELECT id, name FROM Customers WHERE status = 'active';
DCREATE VIEW ActiveCustomers AS SELECT * FROM Customers;
Attempts:
2 left
💡 Hint
Selecting only needed columns can improve performance.
🔧 Debug
advanced
2:00remaining
Why does this CREATE VIEW statement fail?
Consider this SQL statement:

CREATE VIEW EmployeeSummary AS SELECT id, name, salary * 1.1 adjusted_salary FROM Employees;

Why might this statement fail in some SQL databases?
ABecause the alias 'adjusted_salary' is not allowed in views
BBecause some databases require the keyword 'AS' before the alias in the SELECT clause
CBecause you cannot use expressions like salary * 1.1 in a view definition
DBecause the database requires parentheses around the expression salary * 1.1
Attempts:
2 left
💡 Hint
Check the syntax for aliasing columns in SELECT statements inside views.
🧠 Conceptual
expert
2:00remaining
Understanding limitations of CREATE VIEW
Which of the following is NOT a limitation of SQL views created with CREATE VIEW?
AViews cannot contain subqueries in their SELECT statement
BViews cannot have indexes created directly on them
CViews cannot contain ORDER BY clauses unless used with TOP or LIMIT
DViews cannot be used in JOIN operations
Attempts:
2 left
💡 Hint
Think about how views behave like tables in queries.