Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 23rd, 2005, 11:56 AM
Registered User
 
Join Date: Sep 2005
Location: Leicester, , United Kingdom.
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

Reply With Quote
  #2 (permalink)  
Old September 12th, 2007, 03:34 AM
Registered User
 
Join Date: Jul 2007
Location: , , .
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'

Reply With Quote
  #3 (permalink)  
Old September 12th, 2007, 07:08 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 63 Times in 63 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

================================================== =========
Reply With Quote
  #4 (permalink)  
Old September 17th, 2009, 12:55 PM
Registered User
 
Join Date: Jan 2007
Location: Wichita, KS, .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

YOUR post is 2 years old. nanny Nanny PooPoo!!
Reply With Quote
  #5 (permalink)  
Old May 20th, 2011, 06:17 AM
Registered User
 
Join Date: May 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
  #6 (permalink)  
Old September 16th, 2013, 10:11 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2013
Posts: 1
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!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 06:19 PM
Rename a column JENKINSACTIVE SQL Server 2000 3 December 16th, 2004 12:11 AM



All times are GMT -4. The time now is 11:42 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.