这是要翻译的内容:\n\n 有人能找到这个MySQL代码中的错误吗?(初学者)

huangapple go评论60阅读模式
英文:

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

问题

Here's the translated SQL code without the error messages:

CREATE TABLE `students`.`studentinfo` (
id int,
name varchar,
age int
) ENGINE = InnoDB
COMMENT = 'test';

And the modified code without columns:

CREATE TABLE `students`.`studentinfo` (
) ENGINE = InnoDB
COMMENT = 'test';
英文:
CREATE TABLE `students`.`studentinfo` (
id int,
name varchar,
age int
);
ENGINE = InnoDB
COMMENT = 'test';

I am using the MySQL Workbench and I am trying to create a table named students. However my code gives the error message

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
)

I tried to solve this by removing the table like so:

CREATE TABLE `students`.`studentinfo` (
)
ENGINE = InnoDB
COMMENT = 'test';

and even then it still doesn't work! It gives the same error message:

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'

答案1

得分: 1

varchar需要指定长度:

创建表格 students.studentinfo (
id 整数,
name 变长字符(100),
age 整数
)

英文:

varchar needs a length:

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

huangapple
  • 本文由 发表于 2023年7月18日 14:58:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76710209.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定