我正在製作一個ASP.NET網站。在Global.asax中,我有用於初始化某些表的代碼(如果它們不存在)。 init的blog_post和booked_dates部分代碼正確執行並創建表,但是init image_info沒有。它們非常相似,我無法找到MySQL語法有什麼問題。MySQL - CREATE TABLE在類似CREATE TABLE時出錯錯誤
錯誤消息:
您的SQL語法錯誤;檢查對應於你的MySQL服務器版本使用附近的'說明「TEXT,PRIMARY KEY(ID))」在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();
}
感謝事先幫助正確的語法手冊!
在global.asax中創建表並不好主意 – Sergio 2013-03-15 12:08:27