Mysql 执行时Prepare Statement 错误
我试图通过准备语句创建一个表,但它给了我语法错误。 好吧,如果我尝试单独执行相同的语句,那么它就可以正常工作。
这是我的声明 -
SET @Stmt1 = Concat('DROP TABLE IF EXISTS ',DB,'.`county`;\n'
'CREATE TABLE IF NOT EXISTS ',DB,'.`County`
(
`CountyID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`CountyName` VARCHAR(45) NOT NULL,
`CountyCode` VARCHAR(30) NOT NULL,
PRIMARY KEY (`CountyID`)
)');
Prepare stmt2 From @stmt1;
Execute stmt2;
谁能告诉我这个声明中缺少什么? 它在这一行给了我一个错误:
'CREATE TABLE IF NOT EXISTS ',DB,'.`County`
(
`CountyID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
I am trying to create a table though prepare statement but it is giving me syntax error. Well if I try to execute the same statement individually then it works fine.
Here's my statement -
SET @Stmt1 = Concat('DROP TABLE IF EXISTS ',DB,'.`county`;\n'
'CREATE TABLE IF NOT EXISTS ',DB,'.`County`
(
`CountyID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`CountyName` VARCHAR(45) NOT NULL,
`CountyCode` VARCHAR(30) NOT NULL,
PRIMARY KEY (`CountyID`)
)');
Prepare stmt2 From @stmt1;
Execute stmt2;
Please can anyone tell me what am I missing in this statement?
It is giving me an error on this line:
'CREATE TABLE IF NOT EXISTS ',DB,'.`County`
(
`CountyID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://dev.mysql.com/doc/refman/en/prepare。 html 说:
因此,您必须首先执行
DROP TABLE
语句,然后单独准备并执行CREATE TABLE
语句。http://dev.mysql.com/doc/refman/en/prepare.html says:
So you'll have to execute your
DROP TABLE
statement first, and then prepare and execute theCREATE TABLE
statement separately.您在连接中的两个字符串之间没有缺少逗号吗?
应该
are you not missing a comma between the two strings in the concat?
should be