0
0
PostgreSQLquery~10 mins

Views with CHECK OPTION in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a view that only shows employees from the 'Sales' department.

PostgreSQL
CREATE VIEW sales_employees AS SELECT * FROM employees WHERE department = [1];
Drag options to blanks, or click blank then click option'
A'HR'
B'Marketing'
C'Sales'
D'Finance'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the single quotes around the department name.
Using the wrong department name.
2fill in blank
medium

Complete the code to add WITH CHECK OPTION to the view to prevent inserts or updates outside 'Sales'.

PostgreSQL
CREATE VIEW sales_employees AS SELECT * FROM employees WHERE department = 'Sales' [1];
Drag options to blanks, or click blank then click option'
AWITH READ ONLY
BWITH CHECK OPTION
CWITH NO CHECK
DWITH UPDATE OPTION
Attempts:
3 left
💡 Hint
Common Mistakes
Using WITH READ ONLY which disallows all modifications.
Using incorrect or non-existent options.
3fill in blank
hard

Fix the error in the view creation by choosing the correct placement of WITH CHECK OPTION.

PostgreSQL
CREATE VIEW sales_employees AS SELECT * FROM employees WHERE department = 'Sales' [1] WITH CHECK OPTION;
Drag options to blanks, or click blank then click option'
ANO
BAFTER
CBETWEEN
DBEFORE
Attempts:
3 left
💡 Hint
Common Mistakes
Placing WITH CHECK OPTION in the wrong position causing syntax errors.
Adding extra keywords before WITH CHECK OPTION.
4fill in blank
hard

Fill both blanks to create a view that shows only active products and enforces this with CHECK OPTION.

PostgreSQL
CREATE VIEW active_products AS SELECT * FROM products WHERE status = [1] [2];
Drag options to blanks, or click blank then click option'
A'active'
B'inactive'
CWITH CHECK OPTION
DWITH READ ONLY
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'inactive' instead of 'active' in the WHERE clause.
Using WITH READ ONLY which disallows all modifications.
5fill in blank
hard

Fill all three blanks to create a view for employees in 'HR' department with salary over 50000 and enforce it with CHECK OPTION.

PostgreSQL
CREATE VIEW hr_high_salary AS SELECT * FROM employees WHERE department = [1] AND salary > [2] [3];
Drag options to blanks, or click blank then click option'
A'HR'
B50000
CWITH CHECK OPTION
D'Sales'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong department name or salary value.
Forgetting to add WITH CHECK OPTION or placing it incorrectly.