Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update Trigger

Author  Topic 

nangitoholmes
Starting Member

3 Posts

Posted - 2011-03-02 : 10:40:10
Hi all,
I was looking for help with an update triger.
What I want is to run a trigger that will automatically update a table in my database. Eg:
If column a is updated to lets say 10
column b is updated to column a + column b

Is that possible?

What I have tried so far is:

create trigger points_trig
before update on squad

if update(weekly_points)
begin
update latest_points
set latest_points = inserted.weekly_points + latest_points
end

nangitoholmes
Starting Member

3 Posts

Posted - 2011-03-02 : 12:25:25
create trigger points_trig
after update of weekly_points on squad
for each row
EXECUTE PROCEDURE update_points()
end;

CREATE PROCEDURE update_points()
UPDATE squad
SET latest_points = weekly_points + latest_points;

Updated it to this but still gettin errors on the trigger..
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-03-02 : 13:30:33
can you post the ddl of your table?


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

nangitoholmes
Starting Member

3 Posts

Posted - 2011-03-03 : 08:58:59
CREATE TABLE IF NOT EXISTS SQUAD
(
player_id int not null auto_increment primary key,
player_name varchar(25) not null,
player_image varchar(100),
player_dob date not null,
player_position varchar(25) not null,
county_id int not null,
weekly_points int,
latest_points int,
overall_points int
)
;

ALTER TABLE SQUAD
ADD (
CONSTRAINT county_fk FOREIGN KEY (county_id)
REFERENCES counties(county_id)
);

ALTER TABLE SQUAD
ADD (
CONSTRAINT position_fk FOREIGN KEY (player_position)
REFERENCES Position(position_id)
);

Overall points has been dropped since..
Go to Top of Page
   

- Advertisement -