Search code examples
mysqlsqlalter-table

Im having an error when adding a column in SQL


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 'DECIMAL(3, 2)' at line 1

CREATE TABLE student (
    stud_id INT,
    name_f VARCHAR(20),
    email  VARCHAR(20),
    PRIMARY KEY(stud_id)
);

DESCRIBE student;

DROP TABLE student;

ALTER TABLE student ADD DECIMAL(3, 2);

my full code is those.


Solution

  • You are dropping the table before trying to add the new column. Also, you need to give the new column a name.

    This makes more sense:

    CREATE TABLE student (
        stud_id INT,
        name_f VARCHAR(20),
        email  VARCHAR(20),
        PRIMARY KEY(stud_id)
    );
    
    ALTER TABLE student ADD newcol DECIMAL(3, 2);