【问题标题】:MySQL syntax errors using UniServerZ使用 UniServerZ 的 MySQL 语法错误
【发布时间】:2014-11-06 00:10:34
【问题描述】:

我编写了一些 SQL 并运行它以查找几乎所有表中的错误。这是我得到的表格错误:

 Error creating table 'Region': 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 
'desc varchar(25) NOT NULL, PRIMARY KEY(regID))' at line 1

我的代码:

mysql_select_db($dbName, $dbConnection);
$sql = "CREATE TABLE ".$dbTableRegion." (regID int(4) auto_increment NOT NULL, desc varchar(25) NOT NULL, PRIMARY KEY(regID))";
if(mysql_query($sql, $dbConnection))
{
    echo("Table '".$dbTableRegion."' created<br />");
}
else
{
    echo("Error creating table '".$dbTableRegion."': ".mysql_error()."<br />");
}

【问题讨论】:

  • 你可以使用`来括起desc。它是mysql中的系统字

标签: mysql sql syntax


【解决方案1】:

请在此行重命名desc

desc varchar(25) NOT NULL

因为它是 MySQL 中的 reserverd word,所以换成别的东西:

some_stuff varchar(25) NOT NULL

【讨论】:

  • 可以用`括起来
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-19
  • 1970-01-01
  • 2010-12-04
  • 2011-07-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多