English 中文(简体)
MySQL:我如何在触发点使用限制器?
原标题:MySQL: How do I use delimiters in triggers?

有人告诉我,我需要在我的发端中使用限定语。 我看一下MySQL的手册页,我发现这页就是例子;然而,这并不是通用文件。

在这里,我试图纠正:

CREATE TRIGGER adult BEFORE INSERT OR UPDATE ON table5.column5
FOR EACH ROW BEGIN
  UPDATE table1 SET column5 = table5.column5 WHERE table5id = table1xtable5.table5id WHERE table1xtable5.table1id = OLD.table1.id$
END$

很奇怪的是,我不知道如何做到这一点,在。 看来,这种提法过于模糊。 例如,在阅读“old <>/code>和“new时,参考了“subject table--the table associated with thestart. 与这一触发点相关的表格有两张,而Im实际上试图将更多的表格与这一触发点联系起来。 在研究实例代码时,只使用表4中的栏目,即:<编码>UPDATE。 此外,他们还使用<代码>WHERE ~ a3 = New.a1。 我不认为这样做了。 有一个通用的识别码,各表各行各业。 他们当然应当使用独立表,例如适用性。

我实际上今天早些时候曾问过一个类似的问题,即这样做的好方法是什么,但现在我很想知道,是否有办法。 感谢阅读:

这里是更新另一个表格的触发因素的一个例子,但它似乎没有使用一个参数:

CREATE TRIGGER mytrigger BEFORE INSERT ON odp 
FOR EACH ROW
  UPDATE total_points SET points = points + NEW.points;

这一例子中解释的就是<代码>odp和 共计-points重叠。 如何确保<代码>总点表points 浏览量是正确的<条码>点。 <代码>点表中的哪一行? x/

因此,没有办法说明其中哪一个点。 更新<代码>BEFORE INSERT ON odp的行文?

最佳回答

<>第1部分>

划界器用于储存程序/功能、触发或事件等源物体。 所有这些目标都可能有一个机构,即BEGIN......END条款中的法典。

All statement in MySQL scripts should be ended with delimiter, the default is ; . But what to do if source object has body with some statements, e,g:

INSERT INTO table1 VALUES(1);

CREATE PROCEDURE procedure1()
BEGIN
  SET @s =  SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse ;
  PREPARE stmt2 FROM @s;
  SET @a = 6;
  SET @b = 8;
  EXECUTE stmt2 USING @a, @b;
END;

INSERT INTO table1 VALUES(2);

有多少政治家? 页: 1 答案是三,因为文字有两份INSERTs和一份CLE声明。 如你所看到的那样,公民平等委员会也有一些内部声明;我们应当向我的SQL客户说,所有这些声明(在BEGIN......END)都是一份声明的一部分;我们可以在划界人的帮助下:

INSERT INTO table1 VALUES(1);

DELIMITER $$

CREATE PROCEDURE procedure1()
BEGIN
  SET @s =  SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse ;
  PREPARE stmt2 FROM @s;
  SET @a = 6;
  SET @b = 8;
  EXECUTE stmt2 USING @a, @b;
END$$

DELIMITER ;

INSERT INTO table1 VALUES(2);

Note, when your trigger has no BEGIN...END clause, delimiters may be omitted.


<>第2部分>

Without delimiters the statement will be parsed as -

CREATE PROCEDURE procedure1()
BEGIN
  SET @s =  SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse ;

而不是:

CREATE PROCEDURE procedure1()
BEGIN
  SET @s =  SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse ;
  PREPARE stmt2 FROM @s;
  SET @a = 6;
  SET @b = 8;
  EXECUTE stmt2 USING @a, @b;
END
问题回答

a 包括:

delimiter $$

待印发<代码>

UPDATE询问你是否在触发器内运行,这是与任何其他装置一样的最新质询,但这种盘问发生在触发器内。 现在,你重新更新所有记录,并增加实地点。 如果你只希望将其限制在与引发火灾的任何后果有关的特定记录上,那么你就必须在<代码>上添加这一记录。 UPDATE 查询<代码>WHERE条款。

我的SQL知道你对<密码>的意图。 UPDATE 问题是,正如没有任何想法知道你在做正常插入/更新/编辑时真正指的是什么一样,它要求你确切说明必须做些什么。

In the case of an INSERT trigger, there usually isn t an "old" record to refer to, as you re creating something brand new (unless it s an insert ... on duplicate key update situation).





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签