Sample Exam Questions

From the objective of OSS-DB Exam Silver
S3.1 SQL commands (View)

Sample Question


Choose two things you can do with the ALTER VIEW command.

  1. Add a column to a view.
  2. Remove a column from a view.
  3. Change the data type of a column in a view.
  4. Rename a view.
  5. Change the owner of a view.

※This sample exam is different from those that appear in the actual OSS-DB Exam.

Answer and Explanation

To define a view, you use CREATE VIEW. There is an ALTER VIEW command to change the attributes of a defined view, but the only attributes that can be changed are the view name, owner, and schema, and ALTER VIEW can do very little. Note that this is very different from ALTER TABLE which can change most attributes of a table.
To rename a view, use
ALTER VIEW old_view_name RENAME TO new_view_name
for example.
To change the owner of a view, use
ALTER VIEW view_name OWNER TO new_owner
for example.
Changes to the SQL statements that define a view, such as adding columns to a view, can be done with
CREATE OR REPLACE VIEW view_name AS SQL_statement
However, this syntax only allows columns in the existing view to remain in the same order and data type, and append the new column to the end. You cannot drop a column or change its data type even with CREATE OR REPLACE VIEW. You must drop the view with DROP VIEW and then recreate it with CREATE VIEW.

So the correct answers are D and E.