p2p.wrox.com 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 23rd, 2005, 12:56 PM
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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old September 12th, 2007, 04: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'

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old September 12th, 2007, 08:08 AM
Wrox Author
Points: 12,827, Level: 49
Points: 12,827, Level: 49 Points: 12,827, Level: 49 Points: 12,827, Level: 49
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 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

================================================== =========
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old September 17th, 2009, 01:55 PM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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



All times are GMT -4. The time now is 07:19 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc