Skip to main content
Inspiring
October 14, 2006
Question

how to create a new column in an existing table without uploading a new db file

  • October 14, 2006
  • 2 replies
  • 1933 views
hi there, i often find myself needing to add new columns to a table. currently i choose a quiet time of day, download the db from my live server, quickly open it up and add in my new column, then upload it back to the live server - whilst hoping that none of my visitors a) changed anything during this process and b) that no one exeperinced any errors

..not ideal!

is there a way to create new columns in tables (and even to create new tables perhaps) via CF so i dont have to do this downloading / uploading procedure to my mdb documnet (i'm using an access database by the way)

i'm thinking something like this??...

<cfquery datasource="blah">
CREATE COLUMN name="new_variable" type="yes/no"...?
</cfquery>

is there such a thing? thank you very much indeed for any assistance you can provide.
This topic has been closed for replies.

2 replies

Nick WayAuthor
Inspiring
October 15, 2006
ah ha!! - it seems that on this occasion trial and error (as well as the trusty cf forum) was my friend..

in case anyone else finds themselves trying to do what i was doing i now have the following...

<cfquery datasource="blah" >
ALTER TABLE tbl_fred ADD varA BIT
</cfquery>

or (if you want to add a number column to your access db)..

<cfquery datasource="blah" >
ALTER TABLE tbl_fred ADD varB NUMBER
</cfquery>

thanks for your helps chaps
Inspiring
October 14, 2006
Use google it is your friend!

http://www.w3schools.com/sql/sql_alter.asp
Nick WayAuthor
Inspiring
October 14, 2006
hi Simon - thanks for your reply.

naturally i did try google, i tried searching for "coldfusion add column access" and "how to add a column coldfusion" etc - i've also trawled the macromedia knowledge base

i have now tried again searching for "alter table" etc but unfortunatley i am still none the wiser

having read the page you suggested i have tried a few differnent ways of implementing their suggestion - but alas my computer says no..

Error Executing Database Query.
Syntax error in ALTER TABLE statement.

The error occurred in C:\CFusionMX7\wwwroot\nyalocal\admin\testcolumn.cfm: line 1

<cfquery datasource="nya" >
ALTER TABLE tbl_shoots-few ADD city text
</cfquery>

if you or anyone else could please help i'd be very grateful indeed. thank you
Inspiring
October 15, 2006
What database are you using?