我對存儲過程很陌生。我正在嘗試創建一個將記錄插入到兩個不同表中的存儲過程,但我遇到了問題。嘗試使用2個插入創建存儲過程
我使用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語法錯誤;在'in_account'int(11),IN'in_title'varchar(100),IN'in_type'int(2),IN'in_ac'at line附近檢查正確的語法對應的MySQL服務器版本的手冊?1
我在做什麼錯
嘗試一下,不要在參數名稱周圍加引號。即使用IN in_account int(11),而不是IN'in_account'int(11) – Sparky
感謝Sparky,這工作.. – Rick