MySQL -当类似的CREATE TABLE没有't时,CREATE TABLE会出错
本文关键字:CREATE TABLE 出错 没有 MySQL | 更新日期: 2023-09-27 18:03:59
我正在制作一个ASP。. NET网站。在全球。asax我有代码初始化一些表,如果他们不存在。代码的init blog_post和booked_dates部分正确执行并创建了表,但init image_info没有这样做。它们非常相似,我找不到MySQL语法有什么问题。
错误提示:
你有一个错误在你的SQL语法;查看与MySQL服务器版本对应的手册,在第1行
//init blog_post
using (MySqlCommand cmd = new MySqlCommand("CREATE TABLE IF NOT EXISTS `blog_post` (" +
"`id` INT AUTO_INCREMENT," +
"`header` VARCHAR(255)," +
"`bbcode` TEXT," +
"`author` VARCHAR(255)," +
"`time_posted` DATETIME, " +
"PRIMARY KEY(id));", con))
{
cmd.ExecuteNonQuery();
cmd.Dispose();
}
//init booked_dates
using (MySqlCommand cmd = new MySqlCommand("CREATE TABLE IF NOT EXISTS `booked_dates` (" +
"`id` INT AUTO_INCREMENT," +
"`author` VARCHAR(255)," +
"`start_time` DATETIME," +
"`end_time` DATETIME," +
"`time_booked` DATETIME, " +
"PRIMARY KEY(id));", con))
{
cmd.ExecuteNonQuery();
cmd.Dispose();
}
//init image_info
using (MySqlCommand cmd = new MySqlCommand("CREATE TABLE IF NOT EXISTS `image_info` (" +
"`id` INT AUTO_INCREMENT," +
"`author` VARCHAR(255)," +
"`file_name` TEXT," +
"`title` TEXT," +
"`album` TEXT, " +
"'description' TEXT, " +
"PRIMARY KEY(id));", con))
{
cmd.ExecuteNonQuery();
cmd.Dispose();
}
感谢事先的帮助!
您在描述'
周围使用了不同的引号,它应该是另一个
`description`
或者因为description
不是保留字,如果需要,可以省略引号。你的查询应该是:
using (MySqlCommand cmd = new MySqlCommand("CREATE TABLE IF NOT EXISTS `image_info` (" +
"`id` INT AUTO_INCREMENT," +
"`author` VARCHAR(255)," +
"`file_name` TEXT," +
"`title` TEXT," +
"`album` TEXT, " +
"`description` TEXT, " +
"PRIMARY KEY(id));", con))
您没有在创建表代码中使用backticks
。
"'description' TEXT, "
应该"`description` TEXT, "
应该使用backticks
而不是single quote
"'description' TEXT, " +
应该是
"`description` TEXT, " +
"'description' TEXT, " +
有其他引号!
不需要再加引号了