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.
2
Answers
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:
In that case, you can use 2 statements.