This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Views”.
1. In SQL, views can also call as which of the following?
a) Simple Table
b) Virtual Table
c) Actual Table
d) Duplicate Table
View Answer
Explanation: In SQL, Views are the virtual tables that can be created from one or more tables. A view can contain all rows or some selected rows of a table.
2. Which of the following statement is true about views in SQL?
a) We can insert and delete rows in a view
b) We cannot insert and delete rows in a view
c) We can insert but not delete rows in a view
d) We can delete but not insert rows in a view
View Answer
Explanation: In SQL, we can insert and delete rows in a view. We can perform insert and update in an updatable view only. Read-only views are not updatable.
3. Which of the following creates a virtual relation for storing a query?
a) Table
b) Function
c) View
d) Database
View Answer
Explanation: In SQL, a view is only a virtual representation of an already existed table or a view in the database. A view is a relation that is not part of the logical model but can be seen by the user as a virtual relation.
4. In SQL, which of the following statement can be used to create a view?
a)
CREATE VIEW view_name AS FROM TABLE_NAME WHERE condition;
b)
CREATE VIEW view_name AS column1, column2..... columnn TABLE_NAME WHERE condition;
c)
CREATE VIEW view_name ( SELECT column1, column2..... columnn FROM TABLE_NAME WHERE condition);
d)
CREATE VIEW view_name AS SELECT column1, column2..... columnn FROM TABLE_NAME WHERE condition;
Explanation: In SQL, a view can be created using the following statement –
CREATE VIEW view_name AS SELECT column1, column2..... columnn FROM TABLE_NAME WHERE condition;
The CREATE command is used with the VIEW keyword. Column that are to be included in the view are stated along with their table name and a condition if needed.
5. Which of the following can be used to ensure that all the update and insert satisfy the conditions in the view definition?
a) WITH
b) WITH CHECK
c) CHECK
d) IF
View Answer
Explanation: The WITH CHECK option is a CREATE VIEW statement option. The purpose of the WITH CHECK option is to ensure that all UPDATE and INSERTs satisfy the conditions in the view definition.
6. All NOT NULL columns from the base table must be included in the view in order for the INSERT command to function.
a) True
b) False
View Answer
Explanation: In order for the INSERT command to function and enter rows in a view, all the NOT NULL columns from the base table must be included in the view while creating it.
7. In SQL, we can insert rows in a view in a similar way as we insert them in a table.
a) True
b) False
View Answer
Explanation: In SQL, we can insert rows in a view in a similar way as we insert them in a table i.e. by using the INSERT command. But all the NOT NULL columns from the base table must be included in the view in order for the INSERT command to function.
8. Which of the following statement can be used to delete rows from a view?
a)
DELETE FROM View_name FROM TABLE_NAME WHERE condition;
b)
DELETE FROM View_name WHERE condition;
c)
DROP FROM View_name FROM TABLE_NAME WHERE condition;
d)
DROP FROM View_name WHERE condition;
Explanation: The statement that can be used to delete rows from a view is –
DELETE FROM View_name WHERE condition;
The DELETE command is used in a similar way in which we used to delete any row from a table.
9. Which of the following statement can be used to drop a view in SQL?
a) DELETE VIEW view_name FROM Table_name;
b) DROP VIEW view_name FROM Table_name;
c) DROP VIEW view_name;
d) DELETE VIEW view_name;
View Answer
Explanation: The statement that can be used to drop a view in SQL is –
DROP VIEW view_name;
It is similar to dropping a table from a database in SQL.
10. On the basis of number of tables constituted, a view can be classified in how many categories?
a) 2
b) 3
c) 4
d) 5
View Answer
Explanation: There are 2 types of Views in SQL: Simple View and Complex View. Simple views constitute only of a single base table. Complex views can be constituted from more than one base table.
Sanfoundry Global Education & Learning Series – SQL.
To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.