如何将触发器转换为DETERMINISTIC [英] How can I convert trigger to DETERMINISTIC

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

问题描述

如何将此代码转换为DETERMINISTIC呢?



DELIMITER $$

使用`tarfinizbizde` $$

CREATE TRIGGER`tarfinizbizde``tarifler_BEFORE_INSERT`在插入`tarifler`之前每个行

BEGIN



设置新。 tariftarihi = SYSDATE();

END;



我尝试过:



寻找但没有找到

googling

How can i convert this code to DETERMINISTIC one?

DELIMITER $$
USE `tarfinizbizde`$$
CREATE TRIGGER `tarfinizbizde`.`tarifler_BEFORE_INSERT` BEFORE INSERT ON `tarifler` FOR EACH ROW
BEGIN

SET NEW.tariftarihi = SYSDATE();
END;

What I have tried:

looking but nothing found
googling

推荐答案



USE` tarfinizbizde`

USE `tarfinizbizde`




CREATE TRIGGER`tarfinizbizde``tarifler_BEFORE_INSERT`在插入`tarifler`之前为每一行

BEGIN



SET NEW.tariftarihi = SYSDATE();

END;



< b>我尝试了什么:



寻找但没有找到

googling

CREATE TRIGGER `tarfinizbizde`.`tarifler_BEFORE_INSERT` BEFORE INSERT ON `tarifler` FOR EACH ROW
BEGIN

SET NEW.tariftarihi = SYSDATE();
END;

What I have tried:

looking but nothing found
googling






检查这个...



SQL Server Functions:The Basics [ ^ ]



Hi,

Check this...

SQL Server Functions: The Basics[^]

Quote:

确定性函数在使用相同的输入参数集调用时将返回相同的结果。将两个数字加在一起就是确定性函数的一个例子。



另一方面,非确定性函数每次使用相同的集合调用时可能会返回不同的结果输入值。即使数据库中的数据状态相同,函数的结果也可能不同。例如,GETDATE函数是不确定的。几乎所有非确定性函数的一个警告是它们每个语句执行一次,而不是每行执行一次。如果您查询90,000行数据并使用RAND函数尝试为每一行生成一个随机值,您会感到失望; SQL Server只会为整个语句生成一个随机数。此规则的唯一例外是NEWID,它将为语句中的每一行生成一个新的GUID。



当我们创建一个函数时,SQL Server将分析代码我们已经创建并评估了该函数是否具有确定性。如果我们的函数调用任何非确定性函数,它本身就会被标记为不确定函数。 SQL Server依赖SQL CLR函数的作者使用属性将函数声明为确定性。



确定性函数可用于索引视图和计算列,而非确定性函数函数不能。

A deterministic function will return the same result when it is called with the same set of input parameters. Adding two numbers together is an example of a deterministic function.

A nondeterministic function, on the other hand, may return different results every time they are called with the same set of input values. Even if the state of the data in the database is the same, the results of the function might be different. The GETDATE function, for example, is nondeterministic. One caveat of almost all nondeterministic functions is that they are executed once per statement, not once per row. If you query 90,000 rows of data and use the RAND function to attempt to produce a random value for each row you will be disappointed; SQL Server will only generate a single random number for the entire statement. The only exception to this rule is NEWID, which will generate a new GUID for every row in the statement.

When we create a function, SQL Server will analyze the code we've created and evaluate whether the function is deterministic. If our function makes calls to any nondeterministic functions, it will, itself, be marked as nondeterministic. SQL Server relies on the author of a SQL CLR function to declare the function as deterministic using an attribute.

Deterministic functions can be used in indexed views and computed columns whereas nondeterministic functions cannot.







如上文所述,您使用的SYSDATE()是非确定性的。 />




希望这会对你有所帮助。



干杯




as per above text, SYSDATE() which you are using is non-deterministic.


Hope this will help you.

Cheers


这篇关于如何将触发器转换为DETERMINISTIC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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