我应该如何在这种情况下工作.我应该使用 Trigger 还是 Leave on User 来管理 [英] How should i work in this scenario . Should I use Trigger or Leave on User to manage

查看:20
本文介绍了我应该如何在这种情况下工作.我应该使用 Trigger 还是 Leave on User 来管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,我在其中使用存储过程来实现我的逻辑.

I am creating an application in which i am using stored procedure where i m implementing my logic.

现在我需要知道的是 - 我希望我的数据库不包含任何无效条目,为此我应该创建触发器,以实现我的数据验证逻辑,以便在更改 FailPasswordAttemptCount 时到某个值,然后我应该通过触发器相应地更改相应的 IsLocked 列还是将其留给 dba 来管理.

Now what i need to know is that- i want my database not to contain any invalid entry, for this purpose should i create triggers, for implementing my data validation logic such that when FailPasswordAttemptCount is changed to some value then should i make changes in corresponding column IsLocked accordingly thru triggers or leave it on dba to manage.

例如

if FailPassowrdAttemptCount > 3
  IsCaptchaActivated=True
if FailPasswordAttemptCount>6
  IsLocked=true

现在,如果 dba 将 FailPasswordAttemptCount 的值更改为 4,而不将 IsCaptchaActivated 更改为 true,那么这将使我的前端无效.所以我应该通过触发器来管理它还是我应该把它留给 dba 以进行正确的输入.

now if a dba changes the value of FailPasswordAttemptCount to 4 without changing IsCaptchaActivated to true then this will make an invalid entry for my frontend. SO should i manage it thru triggers or should i left it over dba to make correct entry.

虽然这种类型的条目无法通过前端进行,但如果任何人具有访问数据库的权限,则直接通过数据库进行更改.为此,我应该将它留给用户还是应该通过触发器进行管理.我想让我的数据库在所有情况下都保持一致.

Although this type of entry is not possible thru frontend but in case any1 having privilages to access database, changes directly thru database. For this should i leave it on user or should i manage thru triggers. I want to make my database to remain consistent in all circumstances.

推荐答案

我会做到以下几点:

  • 将数据验证逻辑放入存储过程
  • 使存储过程成为应用程序与表交互的唯一方式
  • 将所需代码放入存储过程.

随着应用程序业务逻辑复杂性的增加,基于触发器的编程范式变得越来越难以编码和维护.

Trigger-based programming paradigma grows too hard to code and maintain as the business logic complexity of your application increases.

但是,如果您绝对确定只有这样的简单逻辑,则可以将其放入触发器中,因为这将需要对应用程序与数据库交互的方式进行最少的更改.

However, if you are absolutely sure you will only have the simple logic like this, it is OK to put it into a trigger since this will require minimal changes in the ways the application interacts with the database.

这篇关于我应该如何在这种情况下工作.我应该使用 Trigger 还是 Leave on User 来管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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