search

Home  >  Q&A  >  body text

Can anyone find the error in this MySQL code? (Beginner)

<p><br /></p> <pre class="brush:php;toolbar:false;">CREATE TABLE `students`.`studentinfo` ( id int, name varchar, age int ); ENGINE=InnoDB COMMENT = 'test';</pre> <p>I'm using MySQL workbench and I'm trying to create a table called students. However, my code gives the error message </p> <pre class="brush:php;toolbar:false;">Operation failed: There was an error while applying the SQL script to the database. Executing: CREATE TABLE `students`.`studentinfo` ( id int, name varchar, age int ); ENGINE=InnoDB COMMENT = 'test'; ERROR 1064: 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 ', age int )' at line 3 SQL Statement: CREATE TABLE `students`.`studentinfo` ( id int, name varchar, age int )</pre> <p>I tried to solve the problem by removing the table, like this:</p> <pre class="brush:php;toolbar:false;">CREATE TABLE `students`.`studentinfo` ( ) ENGINE=InnoDB COMMENT = 'test';</pre> <p>Even then, it still doesn't work! It gives the same error message:</p> <pre class="brush:php;toolbar:false;">Operation failed: There was an error while applying the SQL script to the database. Executing: CREATE TABLE `students`.`studentinfo` ( ) ENGINE=InnoDB COMMENT = 'test'; ERROR 1064: 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 ') ENGINE=InnoDB COMMENT = 'test'' at line 2 SQL Statement: CREATE TABLE `students`.`studentinfo` ( ) ENGINE=InnoDB COMMENT = 'test'</pre> <p><br /></p>
P粉469090753P粉469090753489 days ago414

reply all(1)I'll reply

  • P粉590428357

    P粉5904283572023-07-25 13:50:11

    Varchar requires a length:

    CREATE TABLE `students`.`studentinfo` (
    id int,
    name varchar(100),
    age int
    )

    reply
    0
  • Cancelreply