I am using Visual Studio 2008 and SQL Server 2008 Express.
How can I change the name of the view? I can change tables' names, but I can't change the view name.
Any suggestion?
Thank you, Fabio Milheiro
To modify a view In Object Explorer, click the plus sign next to the database where your view is located and then click the plus sign next to the Views folder. Right-click on the view you wish to modify and select Design.
If you remember the CREATE VIEW SQL syntax, a view can be modified by simply using the ALTER VIEW keyword instead, and then changing the structure of the SELECT statement. Therefore, let's change the previously created view with the CREATE VIEW SQL statement by using the ALTER VIEW statement.
Yes underlying table data can be updated by Updating a view. The point to note here is, as long as the View is created based on one single table then direct "Update View" statement would work. But if the view is created based on multiple tables then a direct Update statement won't work.
You can use the ALTER VIEW statement something like this :
ALTER VIEW dbo.myView
AS
SELECT foo
FROM dbo.bar
WHERE widget = 'foo'
GO
Reference on MSDN
To rename a view, use sp_rename
System Stored Procedure :
EXEC sp_rename 'dbo.myView', 'myNewViewName'
Note: don't include the schema name in the second string, or else you'll get a name like "dbo.dbo.myNewViewName".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With