Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases 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 September 23rd, 2005, 11:56 AM
Registered User
 
Join Date: Sep 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Rename a Column using SQL

I have an Access database and wish to change the name of a table column from within an ASP.NET application.

I would prefer to use an SQL statment and an OleDbCommand to do this and then ExecuteNonQuery() etc.

Two possible SQL statements are:

Code:
ALTER TABLE tablename RENAME COLUMN OldName TO NewName
or
Code:
ALTER TABLE tablename RENAME OldName TO NewName
Neither of these statements work and I get an SQL Syntax Error.

Does anyone know what the correct SQL statment is? I can add and remove columns OK using similar SQL statements, just can't rename a column/field!

Cheers

Graham Wilson

 
Old September 12th, 2007, 03:34 AM
Registered User
 
Join Date: Jul 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

EXEC sp_rename
    @objname = 'table_name.old_column_name',
    @newname = 'new_column_name',
    @objtype = 'COLUMN'

 
Old September 12th, 2007, 07:08 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

1. The post is 2 Years old.
2. sp_rename will work in SQL Server, not in access.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET

Professional IIS 7 and ASP.NET Integrated Programming

================================================== =========
The Following User Says Thank You to dparsons For This Useful Post:
anvienhponline (August 11th, 2014)
 
Old September 17th, 2009, 12:55 PM
Registered User
 
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

YOUR post is 2 years old. nanny Nanny PooPoo!!
 
Old May 20th, 2011, 06:17 AM
Registered User
 
Join Date: May 2011
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Default DO it

Quote:
Originally Posted by pipelineconsulting View Post
I have an Access database and wish to change the name of a table column from within an ASP.NET application.

I would prefer to use an SQL statment and an OleDbCommand to do this and then ExecuteNonQuery() etc.

Two possible SQL statements are:

Code:
ALTER TABLE tablename RENAME COLUMN OldName TO NewName
or
Code:
ALTER TABLE tablename RENAME OldName TO NewName
Neither of these statements work and I get an SQL Syntax Error.

Does anyone know what the correct SQL statment is? I can add and remove columns OK using similar SQL statements, just can't rename a column/field!

Cheers

Graham Wilson


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
The Following User Says Thank You to rfulani For This Useful Post:
anvienhponline (August 11th, 2014)
 
Old September 16th, 2013, 10:11 AM
Registered User
 
Join Date: Sep 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Tradition

I feel obligated to revive this thread, as part of a bi-annual tradition started in September of 2005. This thread was then bumped in September 2007, September 2009, and May 2011. From September 2013, I look forward to the response from a tradition-loving soul in September 2015.

Long live sp_rename!
 
Old September 30th, 2015, 11:05 AM
Registered User
 
Join Date: Sep 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Tradition Continues

Happy 10 years to this thread! And once again, a 2 year gap between posts! And once again, long live sp_rename!
 
Old September 21st, 2017, 04:16 PM
Registered User
 
Join Date: Sep 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default The Tradition Never Ends

Happy 12th! Seeya in another two years!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Rename Field using SQL spazband Access 5 May 20th, 2011 06:20 AM
SQL Rename a Field? seananderson BOOK: Beginning SQL 2 May 20th, 2011 06:19 AM
Rename a table through SQL in SQL Server pankaj_daga SQL Server 2000 5 June 27th, 2008 03:31 AM
rename column name dyanmically sudhirbharti SQL Server 2000 3 February 7th, 2008 07:19 PM
Rename a column JENKINSACTIVE SQL Server 2000 3 December 16th, 2004 01:11 AM





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