SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Rename a view
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pooja28
Starting Member

India
6 Posts

Posted - 03/17/2011 :  00:47:32  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
1182 Posts

Posted - 03/17/2011 :  01:02:39  Show Profile  Reply with Quote
sp_rename 'Vemployee','Pemployee'
Go to Top of Page

ahmeds08
Aged Yak Warrior

India
656 Posts

Posted - 03/17/2011 :  01:03:40  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
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 - 03/17/2011 :  01:03:55  Show Profile  Reply with Quote
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

India
6 Posts

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

Thanks & Regards,
Pooja
Go to Top of Page

pk_bohra
Flowing Fount of Yak Knowledge

India
1182 Posts

Posted - 03/17/2011 :  03:33:33  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.27 seconds. Powered By: Snitz Forums 2000