Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access 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 February 20th, 2004, 02:36 PM
Registered User
 
Join Date: Sep 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to spazband Send a message via Yahoo to spazband
Default Rename Field using SQL

I am in the process of writing a utility that will allow for database modifications via SQL. One of the issues I am up against is how to rename a field inside of a table using SQL. This needs to be done because I have to set an index on a field named 'Year' and since this is a key word with Access, the sql statement is giving me fits. I have to rename the field, set the index then rename it back. Everything is done except for the renaming of the field.
 
Old February 20th, 2004, 02:46 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

As an aside you can wrap all names in brackets and they will not be treated as keywords:
Code:
SELECT [Year], [Date] FROM tblCalendar...
--

Joe
 
Old February 20th, 2004, 03:17 PM
Registered User
 
Join Date: Sep 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to spazband Send a message via Yahoo to spazband
Default

That I have done and it will work in Access directly - however it will not sure when running the same query using ADO though a VB front end.
 
Old February 20th, 2004, 03:21 PM
Registered User
 
Join Date: Sep 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to spazband Send a message via Yahoo to spazband
Default

more importantly - I am looking for the proper format of a query that can be used to rename the field of a table. I believe it will be an 'Alter' or 'Update' query. Either way, I am sure that a 'Select' query will not do much for me.
 
Old May 20th, 2011, 06:20 AM
Registered User
 
Join Date: May 2011
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by spazband View Post
I am in the process of writing a utility that will allow for database modifications via SQL. One of the issues I am up against is how to rename a field inside of a table using SQL. This needs to be done because I have to set an index on a field named 'Year' and since this is a key word with Access, the sql statement is giving me fits. I have to rename the field, set the index then rename it back. Everything is done except for the renaming of the field.
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
 
Old May 20th, 2011, 06:20 AM
Registered User
 
Join Date: May 2011
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
Default do

Quote:
Originally Posted by spazband View Post
I am in the process of writing a utility that will allow for database modifications via SQL. One of the issues I am up against is how to rename a field inside of a table using SQL. This needs to be done because I have to set an index on a field named 'Year' and since this is a key word with Access, the sql statement is giving me fits. I have to rename the field, set the index then rename it back. Everything is done except for the renaming of the field.
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
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
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.