【发布时间】:2012-01-06 15:12:57
【问题描述】:
我对存储过程很陌生。我正在尝试创建一个将记录插入两个不同表的存储过程,但我遇到了问题。
我正在使用 C# 编码,使用 .NET 连接到 MySQL。
我有两张桌子,prop_details 和 prop_account。 prop_details 表有一个自增列 (id),prop_account 表定义了一个与 prop_details.id 匹配的外键 prop_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' at line 附近使用正确的语法1
我做错了什么?
【问题讨论】:
-
尝试一下,不要在参数名称周围加上引号。即使用 IN in_account int(11) 而不是 IN 'in_account' int(11)
标签: c# mysql stored-procedures mysql-error-1064