创建触发器的问题 [英] problem with creating trigger

查看:87
本文介绍了创建触发器的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用c#.net在mysql中创建触发器。

我正在尝试使用代码,但给出了语法错误:

 string triggerquery =delimiter $$ CREATE DEFINER =`root` @`localhost`TRIGGER`sectiondb+ ssid +`.`UpdatefaultDuration+ cmid +`
BEFORE INSERT ON`sectiondb1`。 `faultdata+ cmid +`
FOR EACH ROW BEGIN
声明Sh1Status tinyint;
声明Sh1StartTime DateTime;
声明Sh1EndTime DateTime;
选择shift1status,shift1start,shift1end进入Sh1Status,Sh1StartTime,Sh1EndTime
来自`masterdb` .shiftdata`
其中machineid =+ cmid +;结束if; END $$;

解决方案

CREATE DEFINER =`root` @`localhost`TRIGGER`sectiondb+ ssid +`.`UpdatefaultDuration+ cmid +`
BEFORE INSERT ON`sectiondb1` .`faultdata+ cmid +`
FOR EACH ROW BEGIN
声明Sh1Status tinyint;
声明Sh1StartTime DateTime;
声明Sh1EndTime DateTime;
选择shift1status,shift1start,shift1end到Sh1Status,Sh1StartTime,Sh1EndTime
来自`masterdb` .shiftdata`
where machineid =+ cmid +; end if; END

< br>

;


1.如果你连接使用String.Format或更好的stringBuilder.AppendFormat ...你可以这样编写没有所有这些优点,更容易看到正确关闭所有报价。



2.你应该首先在数据库中写入触发器然后完成你知道会工作的触发器复制并转换为代码部分。





最后,在不知道变量的确切值(可能导致连接错误)和你的数据库(通过SELECT INTO结构我会说这是oracle吗?)有点难以知道触发器应该是什么样的。



语法错误在哪一行?

I want to create trigger in mysql using c#.net.
I am trying following code but it gives syntax error:

string triggerquery= "delimiter $$ CREATE DEFINER=`root`@`localhost` TRIGGER `sectiondb" + ssid + "`.`UpdatefaultDuration"+cmid+"` 
BEFORE INSERT ON `sectiondb1`.`faultdata" + cmid + "` 
FOR EACH ROW BEGIN 
declare Sh1Status tinyint;
declare Sh1StartTime DateTime; 
declare Sh1EndTime DateTime;
select shift1status,shift1start,shift1end into Sh1Status,Sh1StartTime,Sh1EndTime 
from `masterdb`.`shiftdata` 
where machineid=" + cmid + ";end if;END $$";

解决方案

CREATE DEFINER=`root`@`localhost` TRIGGER `sectiondb" + ssid + "`.`UpdatefaultDuration"+cmid+"` BEFORE INSERT ON `sectiondb1`.`faultdata" + cmid + "` FOR EACH ROW BEGIN declare Sh1Status tinyint; declare Sh1StartTime DateTime; declare Sh1EndTime DateTime; select shift1status,shift1start,shift1end into Sh1Status,Sh1StartTime,Sh1EndTime from `masterdb`.`shiftdata` where machineid=" + cmid + ";end if;END


";


1. if you're concatenating use String.Format or better stringBuilder.AppendFormat...that way you can write without all those pluses and see more easily about closing all quotes properly.

2. You should write the trigger in the database first and then finished trigger that you know will work copy and transform into code part.


Finally, without knowing exact values of your variables (which can cause errors in concatenation) and your database (by SELECT INTO structure I'd say this is oracle?) it's kinda hard to know how the trigger should look.

Syntax error on which line?


这篇关于创建触发器的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆