0

我对这个查询有疑问。

 $query = 'CREATE TABLE movie(
    movie_id UNSIGNED INTEGER NOT NULL AUTO_INCREMENT,
    movie_name VARCHAR(255) NOT NULL,
    movie_type TINYINT NOT NULL DEFAULT 0,
    movie_year SMALLINT UNSIGNED NOT NULL DEFAULT 0,
    movie_leadactor INTEGER UNSIGNED NOT NULL DEFAULT 0,
    movie_director INTEGER UNSIGNED NOT NULL DEFAULT 0,

    PRIMARY KEY (movie_id),
    KEY movie_type (movie_type, movie_year)
    )
    ENGINE=MyISAM';
 $result = mysql_query($query, $db) or die(mysql_error($db));

它仍然这样写:

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 2 行的“UNSIGNED INTEGER NOT NULL AUTO_INCREMENT, movie_name VARCHAR(255) NOT NULL,”附近使用正确的语法

4

3 回答 3

3

无符号必须在 int 之后。我重写了您的查询并验证它现在确实有效。

CREATE TABLE movie(
movie_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
movie_name VARCHAR(255) NOT NULL,
movie_type TINYINT NOT NULL DEFAULT 0,
movie_year SMALLINT UNSIGNED NOT NULL DEFAULT 0,
movie_leadactor INT UNSIGNED NOT NULL DEFAULT 0,
movie_director INT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (movie_id),
KEY movie_type (movie_type, movie_year)
)
ENGINE=MyISAM
于 2012-11-19T20:11:16.787 回答
0

试试这个,你的 INTEGER 可以写成 INT 并且你把 UNSIGNED 变量放在它之前,它需要去后面 -

$query = 'CREATE TABLE movie(
`movie_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`movie_name` VARCHAR(255) NOT NULL,
`movie_type` TINYINT NOT NULL DEFAULT 0,
`movie_year` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`movie_leadactor` INTEGER UNSIGNED NOT NULL DEFAULT 0,
`movie_director` INTEGER UNSIGNED NOT NULL DEFAULT 0,

PRIMARY KEY (movie_id),
KEY movie_type (movie_type, movie_year)
)
ENGINE=MyISAM';
$result = mysql_query($query, $db) or die(mysql_error($db));
于 2012-11-19T20:12:06.957 回答
0

MySQL 的整数类型称为INT,而不是INTEGER

于 2012-11-19T20:09:36.957 回答