|
-
Jan 21st, 2000, 05:10 PM
#1
Thread Starter
New Member
Hi,
Does anybody have an example of sql server trigger for an update?
Gil
-
Jan 22nd, 2000, 12:11 PM
#2
Guru
Hi Gil
This is something I threw together, it checks to see if a value already exists, and raises an error if it does.
Code:
CREATE TRIGGER tr_test ON [Names]
FOR INSERT
AS
-- Declare variables
Declare @NewName varchar(50)
Declare @MyCount int
-- Get Name of inserted value
Select @NewName = inserted.[name] from inserted
-- Get Count
Select @MyCount = count(*) from Names where [Name] = @NewName
-- Check to see if it already exists
if @MyCount > 1
BEGIN
-- roll back change, raise error
ROLLBACK
RAISERROR ('NAME ALREADY EXISTS!', 16, 1)
END
-
Jan 22nd, 2000, 06:04 PM
#3
Thread Starter
New Member
Thanks,
It wasn't exactly what I need but it gave me a starting point.
I am adding an example of update trigger for everybody.
Code:
-------------------------------------------
CREATE TRIGGER IntUpdate ON appIntD
FOR update
AS
declare @newkod int
declare @oldkod int
select @oldkod = deleted.kod from deleted
select @newkod = inserted.kod from inserted
if update(kod)
begin
update appIntLinD
set intr=@newkod
where intr= @oldkod
end
-------------------------------------------
gil
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|