```go
func createTable(db *sql.DB, table string) {
sql := `
DROP TABLE IF EXISTS ` + table + `;
CREATE TABLE ` + table + `(
uid INT(10) NOT NULL AUTO_INCREMENT,
username VARCHAR(64) NULL DEFAULT NULL,
departname VARCHAR(64) NULL DEFAULT NULL,
created DATE NULL DEFAULT NULL,
PRIMARY KEY(uid)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;`
fmt.Println("\n" + sql + "\n")
smt, err := db.Prepare(sql)
checkErr(err)
smt.Exec()
}
```
这是我打印的调试信息:
DROP TABLE IF EXISTS tablea;
CREATE TABLE tablea(
uid INT(10) NOT NULL AUTO_INCREMENT,
username VARCHAR(64) NULL DEFAULT NULL,
departname VARCHAR(64) NULL DEFAULT NULL,
created DATE NULL DEFAULT NULL,
PRIMARY KEY(uid)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
panic: Error 1064: 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 'CREATE TABLE tablea(
uid INT(10) NOT NULL AUTO_INCREMENT,
username VARCHAR(64)' at line 22
这是为什么捏?
有疑问加站长微信联系(非本文作者)