0

I'm just playing around with SQL for the first time at the moment and I've been trying to add new columns to an existing table for a student registry sort of deal.

I've followed a few tutorials online and they're all pointing to what I've been trying so far which is basically this:

ALTER TABLE students 
ADD 
allergies VARCHAR(255), 
afterSchoolActivities VARCHAR(255);

Based on the stuff I've read and the tutorials I've watched, it should work, but phpmyadmin displays an error message:

1 errors were found during analysis.

Unrecognized alter operation. (near "" at position 0)

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'VARCHAR(255)' at line 1

I'm pretty sure there's something here tha I'm missing, but I've been staring at this for a while and cannot seem to figure it out. Thought I'd reach out to this amazing community for help.

P.S: Apologies for the poor code formatting, I've been trying to post this question for nearly an hour indenting and trying everything else, but it just doesn't seem to work. EDIT: Somehow managed to fix it after posting.

0

2 Answers 2

0

Right, so after going back and forth for a while, I realized that what was happening was that I wasn't specifying what should happen after the comma. I assumed it was implied after the first ADD, but apparently it is not.

For anyone else who happens to get stuck like I did, what seemed to have fixed the issue was this:

ALTER TABLE students 
ADD allergies VARCHAR(255),
ADD afterSchoolActivities VARCHAR(255);
0

I'm trying to add both "allergies" and "afterSchoolActivities"

In that case, you can use 2 statements.

ALTER TABLE students
ADD COLUMN allergies VARCHAR(255);

ALTER TABLE students
ADD COLUMN afterSchoolActivites VARCHAR(255);
1
  • just to clarify, I'm trying to add both "allergies" and "afterSchoolActivities" to the table rather than trying to add "allergies" AFTER "SchoolActivities" - if that makes sense? I have tried altering the code to: ALTER TABLE students ADD COLUMNS allergies VARCHAR(255), afterSchoolActivities VARCHAR(255); Unfortunately, still no luck. Mar 28, 2019 at 9:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.