I am trying to add a column to my table before another column using BEFORE, I can’t use AFTER because the column names before aren’t a constant. This is what I have:
ALTER TABLE testfyf ADD intake_10_2013 VARCHAR(20) NOT NULL BEFORE url;
Everything up until BEFORE is working.
Before anyone says anything about this, I know adding columns this way is not a good idea, but it is what my boss wants.
Does anyone know how I can achieve this? I have found plenty of examples that say this should work but it doesn’t.
MySQL (if this is mysql – you just tagged it
sqlgenerically) does not support aBEFOREkeyword. You will have to find out the name of the previous column and add it withAFTER.You can use this statement to list the column names and determine programmatically with PHP after which one your new one should be placed.
Here’s a function that should return the column before ‘url’. I didn’t test it but I think it will do the job.
Now you can do: