CREATE TABLE查询无效

时间:2013-09-29 08:37:48

标签: php mysql sql mysqli

$con->query("CREATE TABLE jobs
(
ID INT AUTO_INCREMENT,
Title VARCHAR(32),
Company VARCHAR(32),
Country VARCHAR(32),
City VARCHAR(32),
Email VARCHAR(32),
Website VARCHAR(32),
Description VARCHAR(1000)
);");

有谁知道为什么它不起作用?

提前致谢

4 个答案:

答案 0 :(得分:4)

如果列为AUTO_INCREMENT,则您只能将其定义为PRIMARY KEY

因此,只需将PRIMARY KEY添加到AUTO INCREMENT列,就像这样:

CREATE TABLE jobs
(
ID INT AUTO_INCREMENT,
Title VARCHAR(32),
Company VARCHAR(32),
Country VARCHAR(32),
City VARCHAR(32),
Email VARCHAR(32),
Website VARCHAR(32),
Description VARCHAR(1000),
PRIMARY KEY (ID)
);

答案 1 :(得分:0)

Because there was no primary key defined,try this

CREATE TABLE jobs
(
    ID INT AUTO_INCREMENT PRIMARY KEY,
    Title VARCHAR(32),
    Company VARCHAR(32),
    Country VARCHAR(32),
    City VARCHAR(32),
    Email VARCHAR(32),
    Website VARCHAR(32),
    Description VARCHAR(1000)
);

答案 2 :(得分:0)

Incorrect table definition; 
there can be only one auto column and it must be defined as a key

将主键添加到ID

ID INT AUTO_INCREMENT PRIMARY KEY,

答案 3 :(得分:0)

  

是的,我也没有任何错误

应该

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

在您的代码中使用此行,您将立即了解问题,并在不浪费社区力量的情况下解决问题。