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
 Trigger problem - updating an other table for equa

Author  Topic 

runningdap
Starting Member

1 Post

Posted - 2010-06-08 : 10:16:06
hey everyone, sorry if this has been answered before, couldnt find anything .Here we go:

there are two tables:

create table songs(song_name text, song_artist text,song_url text, song_cat text, last_edit text);
create table categories(cat_name text, cat_total int);


im trying to create a trigger that, when i insert a new song in the songs table, it will check the category of the song (song_cat) and increase the respective cat_total (from table categories) by 1.
here is what i've done so far:

drop trigger countcat;
CREATE TRIGGER countcat AFTER INSERT ON songs FOR EACH ROW
update categories SET cat_total= cat_total +1
WHERE cat_name = (select song_cat FROM inserted);

the truth is that i have no idea what to write in the cat_name = (select ...). I have tried lots of stuff but still nothing.
when i use this, i get the error that mydatabase.inserted doesnt exist

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-08 : 10:23:31
Is that ORACLE?
This is a MS SQL Server forum and there is no "FOR EACH ROW" in a trigger.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-08 : 10:37:07
Post your question at www.orafaq.com

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -