T-SQL » Views » Modifying a View

Syntax:
ALTER VIEW view_name [ ( column1, ... ) ]
[ WITH ENCRYPTION ]
AS
    select_statement
[ WITH CHECK OPTION ]

A View can be modified by:

  1. Deleting the existing view and creating a new one.
  2. Using the ALTER VIEW T-SQL command.
Modifying a view does not change any of the dependents on the view, but the dependents are lost when a view is recreated. The parameters from the ALTER VIEW statement are the same as those for the CREATE VIEW statement.

Examples

Code:
ALTER VIEW vwStudentDetails
AS
SELECT * FROM Students
WHERE Std_Grade=1;


SELECT * FROM vwStudentDetails;
Output:
The command(s) completed successfully.


IdNameStd_CoursePhoneStd_Grade
3Harri Robins3787881





(1 row(s) affected)
Explanation:

This example alters the view created earlier, and then executes it.

Language(s): MS SQL Server