• 0

MySQL Syntax for Adding Column to Table


Question

I am trying to insert a column into a table to keep track of historical data. I get an error saying my syntax is incorrect:

Notice: Query: ALTER TABLE historical_populations ADD COLUMN January 2000 VARCHAR(20) AFTER December 1999

MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2000 VARCHAR(20) AFTER December 1999'

Here is my query:


//update historical population table
$q = "ALTER TABLE historical_populations ADD COLUMN $this_tick VARCHAR(20) AFTER $last_tick";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br/>MySQL Error: " . mysqli_error($dbc));
[/CODE]

$this_tick might hold something like January 2000, while $last_tick might hold Decemember 1999. I have already tried adding single quotes around the variables...

What am I doing wrong?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

This topic is now closed to further replies.