Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

one row trigger

 
natx
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could someone help me please?
Although the following triggers dont give me any syntax error. Every time a user inserts or updates a record, the region field in the member table is set to NULL.
This is the code:
CREATE TRIGGER [regiontree] ON [member]
FOR INSERT, UPDATE
AS
DECLARE @userid integer, @country nvarchar
SELECT @userid = member.userid, @country = member.country
FROM inserted, member
IF @userid = member.userid
BEGIN
UPDATE [member]
SET region = Region.area
FROM Region
WHERE Region.country = member.country
END
------------------------------------
CREATE TRIGGER [regiontree] ON [member]
FOR INSERT, UPDATE
AS
SELECT i.userid = m.userid
FROM inserted i, member m
IF i.userid = m.userid
BEGIN
UPDATE [member]
SET region = Region.area
FROM Region
WHERE Region.country = member.country
END
---------------------------------------
CREATE TRIGGER [regiontree] ON [member]
FOR INSERT, UPDATE
AS
UPDATE [member]
SET member.region = Region.area
FROM
[member]
JOIN Region ON Region.country = member.country
JOIN inserted ON inserted.userid = member.userid
Thanks so much
natalia http://www.nataliaz.com
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!