Wrox Programmer Forums
|
BOOK: Beginning SQL
This is the forum to discuss the Wrox book Beginning SQL by Paul Wilton, John Colby; ISBN: 9780764577321
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning SQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 23rd, 2006, 06:33 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL Rename a Field?

ALTER TABLE TEST2 RENAME NEWFIELD2 TO NEWCOLUMN

I am trying to rename a column in a query, but it fails wth the following error:

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'NEWFIELD2'.

I also noted that in SQL Query Analyzer that the colour coding of the query indicates that RENAME isn't a correct command (ie: not shown in blue)

I also had the same problem when I tried to rename a whole table.

Any advice?

Regards,

Sean Anderson
__________________
Regards,

Sean Anderson
 
Old November 23rd, 2006, 07:29 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii seananderson!!
Hope this will help you
http://p2p.wrox.com/topic.asp?TOPIC_ID=15190

Other Articles
http://msdn2.microsoft.com/en-US/library/ms188351.aspx
http://www.functionx.com/sqlserver/Lesson05b.htm
http://databases.aspfaq.com/database...-a-column.html

Cheers :)

vinod
 
Old May 20th, 2011, 06:19 AM
Registered User
 
Join Date: May 2011
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by seananderson View Post
ALTER TABLE TEST2 RENAME NEWFIELD2 TO NEWCOLUMN

I am trying to rename a column in a query, but it fails wth the following error:

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'NEWFIELD2'.

I also noted that in SQL Query Analyzer that the colour coding of the query indicates that RENAME isn't a correct command (ie: not shown in blue)

I also had the same problem when I tried to rename a whole table.

Any advice?

Regards,

Sean Anderson

to rename

for eg chenge column name for fnmae to fname in table employee

step 1 rename employee to employe
step 2 create table employee (fname,lname , and other columns of table) as select * from employe.

then drop employe
and add constraints againn to employee if any exist.

alter table do not change name of column , table and size of column if table data exist





Similar Threads
Thread Thread Starter Forum Replies Last Post
Rename a Column using SQL pipelineconsulting Classic ASP Databases 7 September 21st, 2017 04:16 PM
Rename Field using SQL spazband Access 5 May 20th, 2011 06:20 AM
Rename a table through SQL in SQL Server pankaj_daga SQL Server 2000 5 June 27th, 2008 03:31 AM
How to rename a table in SQL Server leo_vinay Classic ASP Databases 1 January 5th, 2005 12:48 AM
sql expression field zouky Crystal Reports 0 October 29th, 2004 02:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.