Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Rename a view

Author  Topic 

pooja28
Starting Member

6 Posts

Posted - 2011-03-17 : 00:47:32
Hi to all,
I created following table and its view.

create table employee(id integer, name varchar(20), age integer)

create view Vemployee as select id, name from employee.


now I want to rename a view, so I wrote a query like

rename view Vemployee to Pemployee

But, it shows error about 'raname' keyword.

what to do for renaming a view?



Thanks & Regards,
Pooja

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2011-03-17 : 01:02:39
sp_rename 'Vemployee','Pemployee'
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2011-03-17 : 01:03:40
it is recommended that you never rename a view for some reasons.you need to drop it a recreate it.
but any ways to rename a view "SP_RENAME 'OLDNAME,'NEWNAME'"
Go to Top of Page

subhbwn
Starting Member

6 Posts

Posted - 2011-03-17 : 01:03:55
AS MSDN says : "Renaming a view does not change the name of the view in the text of the view's definition. To change the name of the view in the definition, modify the view directly."

You DROP the view and then create a new one. You can refer to http://www.w3resource.com/sql/drop/drop-view.php and http://www.w3resource.com/sql/creating-views/creating-view.php.Hope this will be useful for you.
Go to Top of Page

pooja28
Starting Member

6 Posts

Posted - 2011-03-17 : 01:05:06
@pk_bohra.....is it work with sql server 2000 also?

Thanks & Regards,
Pooja
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2011-03-17 : 03:33:33
quote:
Originally posted by pooja28

@pk_bohra.....is it work with sql server 2000 also?

Thanks & Regards,
Pooja



AFAIK yes it works even in SQL 2000.
Go to Top of Page
   

- Advertisement -