简体   繁体   中英

Table creation in MySQL results in a vague error

I'm trying to create a table "Student" in MySQL,
However, I'm unable to debug the error.

CREATE TABLE STUDENT (
-> No INT NOT NULL,
-> Name VARCHAR(100) NOT NULL,
-> STIPEND DECIMAL(5,2),
-> STREAM VARCHAR,
-> AVGMARKS DECIMAL(3,1),
-> GRADE CHAR(1),
-> CLASS CHAR(3));
ERROR 1064 (42000): 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 AVGMARKS DECIMAL(3,1), GRADE CHAR(1), CLASS CHAR(3))' at line 5`

Any help would be appreciated.
I hope data types and column names are self-explanatory.
I've wasted 40mins of my life correcting this pathetic code

A varchar column needs a length, as explained in the documentation :

The CHAR and VARCHAR types are declared with a length that indicates the maximum number of characters you want to store. For example, CHAR(30) can hold up to 30 characters.

Consider:

CREATE TABLE STUDENT (
    No INT NOT NULL,
    Name VARCHAR(100) NOT NULL,
    STIPEND DECIMAL(5,2),
    STREAM VARCHAR(10),     --> here
    AVGMARKS DECIMAL(3,1),
    GRADE CHAR(1),
    CLASS CHAR(3)
);

It could be in STREAM VARCHAR

You have to define the number of character in VARCHAR. Try VARCHAR(100) to see if this works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM