MySQL不会允许VARCHAR作为主键吗?

5 mysql sql unique primary-key unique-constraint

我正在尝试创建一个名为Students的表,只有一个字段student_name.

student_name应该是VARCHAR和主键,因为我想通过他们的名字唯一地标识学生.

CREATE TABLE 'swinters'.'Students' (
  'student_name' VARCHAR NOT NULL,
  PRIMARY KEY ('student_name')
)
ENGINE = InnoDB;
Run Code Online (Sandbox Code Playgroud)

MYSQL Error Number 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 'NOT NULL, PRIMARY KEY ('student_name') ) ENGINE = InnoDB' at line 2.

MYSQL Error Number 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 'NOT NULL, PRIMARY KEY ('student_name') ) ENGINE = InnoDB' at line 2.

MYSQL Error Number 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 'NOT NULL, PRIMARY KEY ('student_name') ) ENGINE = InnoDB' at line 2.

zer*_*kms 9

您需要指定VARCHAR(N),其中N最大字符串长度


Fos*_*sco 6

您需要提供VARCHAR列的长度.即VARCHAR(255)