好象只能用触发器 Create trigger yourTriggerName on yourTable For Insert,Update As If Exists(Select * from yourTable a Join Inserted b on a.yourField = b.yourField where b.yourField is not null) Begin RollBack Transaction End
Create trigger yourTriggerName on yourTable For Insert,Update As If Exists(Select * from yourTable a Join Inserted b on a.yourField = b.yourField where b.yourField is not null) Begin RollBack Transaction End
you can use 'uniqueidentifier' nullable as the field type.
to arbinger(阿彬哥),how to use
to Rivulet119(之江滔滔) ,如何用程序调用存储过程
Create trigger yourTriggerName on yourTable For Insert,Update As If Exists(Select * from yourTable a Join Inserted b on a.yourField = b.yourField where b.yourField is not null) Begin RollBack Transaction End如何用程序调用存储过程 exec yourstoredprocedurename parameter1,paremeter2,...
to woyaofengle(清流2号) Create trigger yourTriggerName on yourTable For Insert,Update As If Exists(Select * from yourTable a Join Inserted b on a.yourField = b.yourField where b.yourField is not null) Begin RollBack Transaction End 这段代码是写在数据库中吗
多谢楼上这位仁兄指点,我还有一个问题,既然触发器是一种特殊类型的存储过程,我将 Create trigger yourTriggerName on yourTable For Insert,Update As If Exists(Select * from yourTable a Join Inserted b on a.yourField = b.yourField where b.yourField is not null) Begin RollBack Transaction End 这段代码写在新建存储过程中应该没错吧,为什么会提示有误呢?(代码无误)
"这段代码写在新建存储过程中应该没错吧,为什么会提示有误呢?(代码无误)"触发器和存储过程是SQL中的两个不同的对象,你可以在查询分析器中直接运行你的:Create trigger yourTriggerName on yourTable For Insert,Update As If Exists(Select * from yourTable a Join Inserted b on a.yourField = b.yourField where b.yourField is not null) Begin RollBack Transaction End 如果没有错误的话,触发器就生成好了。要修改触发器可以: 1.使用Alter Trigger语句 2.在企业管理器中直接图形化修改:选择表-->设计表-->选择触发器图标(两个像烽火台一样的东东)
语句: If Exists(Select * from yourTable a Join Inserted b on a.yourField = b.yourField where b.yourField is not null) 有错!少了Inner 改为: If Exists(Select * from yourTable a Inner Join Inserted b on a.yourField = b.yourField where b.yourField is not null)
Create trigger yourTriggerName on yourTable
For Insert,Update
As
If Exists(Select * from yourTable a Join Inserted b on a.yourField = b.yourField where b.yourField is not null)
Begin
RollBack Transaction
End
触发器是一种特殊类型的存储过程,当使用下面的一种或多种数据修改操作在指定表中对数据进行修改时,触发器会生效:UPDATE、INSERT 或 DELETE。触发器可以查询其它表,而且可以包含复杂的 SQL 语句。它们主要用于强制复杂的业务规则或要求。例如,可以控制是否允许基于顾客的当前帐户状态插入定单。触发器还有助于强制引用完整性,以便在添加、更新或删除表中的行时保留表之间已定义的关系。然而,强制引用完整性的最好方法是在相关表中定义主键和外键约束。如果使用数据库关系图,则可以在表之间创建关系以自动创建外键约束。有关详细信息,请参见表关系。使用触发器的优点
触发器的优点如下: 触发器是自动的:它们在对表的数据作了任何修改(比如手工输入或者应用程序采取的操作)之后立即被激活。
触发器可以通过数据库中的相关表进行层叠更改。例如,可以在 titles 表的 title_id 列上写入一个删除触发器,以使其它表中的各匹配行采取删除操作。该触发器用 title_id 列作为唯一键,在 titleauthor、sales 及 roysched 表中对各匹配行进行定位。
触发器可以强制限制,这些限制比用 CHECK 约束所定义的更复杂。与 CHECK 约束不同的是,触发器可以引用其它表中的列。例如,触发器可以回滚试图对价格低于 10 美元的书(存储在 titles 表中)应用折扣(存储在 discounts 表中)的更新。
For Insert,Update
As
If Exists(Select * from yourTable a Join Inserted b on a.yourField = b.yourField where b.yourField is not null)
Begin
RollBack Transaction
End
1.在后台创建一存储过程,将新的输入值作为参数传入,在存储过程中检查该字段值是否存在。存在或不存在返回不同的值。
2.在前台该字段输入的控件失去焦点时,调用该存储过程,判断值是否已存在。这样处理,比在后台使用触发器效率高。
Create trigger yourTriggerName on yourTable
For Insert,Update
As
If Exists(Select * from yourTable a Join Inserted b on a.yourField = b.yourField where b.yourField is not null)
Begin
RollBack Transaction
End如何用程序调用存储过程
exec yourstoredprocedurename parameter1,paremeter2,...
Create trigger yourTriggerName on yourTable
For Insert,Update
As
If Exists(Select * from yourTable a Join Inserted b on a.yourField = b.yourField where b.yourField is not null)
Begin
RollBack Transaction
End
这段代码是写在数据库中吗
如在Delphi中,提供了专门的调用存储过程的控件,你只需在控件中设置调用的存储过程的名称、参数等。
Create trigger yourTriggerName on yourTable
For Insert,Update
As
If Exists(Select * from yourTable a Join Inserted b on a.yourField = b.yourField where b.yourField is not null)
Begin
RollBack Transaction
End
这段代码写在新建存储过程中应该没错吧,为什么会提示有误呢?(代码无误)
Begin Transaction
中间代码.commit Transaction
For Insert,Update
As
If Exists(Select * from yourTable a Join Inserted b on a.yourField = b.yourField where b.yourField is not null)
Begin
RollBack Transaction
End
如果没有错误的话,触发器就生成好了。要修改触发器可以:
1.使用Alter Trigger语句
2.在企业管理器中直接图形化修改:选择表-->设计表-->选择触发器图标(两个像烽火台一样的东东)
If Exists(Select * from yourTable a Join Inserted b on a.yourField = b.yourField where b.yourField is not null) 有错!少了Inner
改为:
If Exists(Select * from yourTable a Inner Join Inserted b on a.yourField = b.yourField where b.yourField is not null)