尝试使用2个插入创建存储过程

时间:2011-11-25 21:03:00

标签: c# mysql stored-procedures mysql-error-1064

我对存储过程很新。我正在尝试创建一个存储过程,将记录插入两个不同的表,但我遇到了问题。

我正在使用.NET连接器向C#编写代码。

我有两个表,prop_detailsprop_accountprop_details表有一个自动增量列(id),prop_account表定义了一个匹配prop_id的外键prop_details.id

以下伪代码解释了存储过程应该做什么:

insert form elements into table prop_details
insert relationship of prop_details.id into table prop_account

这是我尝试创建的存储过程

DROP PROCEDURE IF EXISTS `InsertPropertybyClientID`;

CREATE DEFINER = `root`@`localhost` PROCEDURE `InsertPropertybyClientID`(IN 'in_account' int(11), IN `in_title` varchar(100), IN 'in_type' int(2), IN 'in_active' tinyint(1), IN 'in_created' datetime)
BEGIN
INSERT INTO prop_details 
    (prop_title, prop_type, prop_active)
VALUES 
    (in_title, in_type, in_active, in_created);

INSERT INTO prop_account
    (prop_id, acnt_id)
VALUES
    (LAST_INSERT_ID(), in_account);
END;

尝试保存存储过程时,我收到此错误

  

1064 - 您的SQL语法出错;查看与您的MySQL服务器版本相对应的手册,以便在“'in_account'int(11),IN'in_title'varchar(100),IN'in_type'int(2),IN'in_ac'在线附近使用正确的语法1

我做错了什么?

1 个答案:

答案 0 :(得分:2)

实际上,错误细节表达了错误:

  

near"' in_account' int(11),IN' in_title' varchar(100),IN' in_type' int(2),IN' in_ac'在第1行

identifiers的MySQL参考文档中,它声明:

  

标识符引号字符是反引号(“`”):

  

如果启用了ANSI_QUOTES SQL模式,也允许在双引号内引用标识符:

这意味着除非您启用ANSI_QUOTES SQL模式,否则不应使用单引号或双引号来表示标识符。如果您使用的单词不是reserved word,则可以使用用户反引号(`),也可以省略反引号。

相关问题