Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Mulit row update triggers


Mulit row update triggers

Author
Message
Jeff W
Jeff W
Old Hand
Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)

Group: General Forum Members
Points: 353 Visits: 51
How can I create an update trigger that can allow for multiple rows being updated at the same time? I recieve this error now:

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. [SQLSTATE 21000] (Error 512) The statement has been terminated. [SQLSTATE 01000] (Error 3621). The step failed.


"Keep Your Stick On the Ice" ..Red Green
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: Administrators
Points: 36453 Visits: 18764
Can you post your code? Basically you have to code your trigger as though you are joining a table, not a single value.

Steve Jones
sjones@sqlservercentral.com
http://www.sqlservercentral.com/columnists/sjones

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Jeff W
Jeff W
Old Hand
Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)

Group: General Forum Members
Points: 353 Visits: 51
Thanks Steve, I had been testing things and finally worked through it, and you were dead on with that. Here is the before and after code in case anyone else may be interested.

Before....didn't work............
..
..
IF (SELECT HospitalID FROM deleted) IN (1098,2440,2481,2770,4165,4427,4603,6184,6564)
BEGIN
INSERT INTO [Nursery_Transactions]
SELECT 'D',
[HospitalID],
[CollageID],
GETDATE()
FROM deleted
END
..
..
After.......did work..........
..
..
INSERT INTO [Nursery_Transactions]
SELECT 'U',
[HospitalID],
[CollageID],
GETDATE()
FROM deleted
WHERE deleted.[HospitalID] IN (1098,2440,2481,2770,4165,4427,4603,6184,6564)


"Keep Your Stick On the Ice" ..Red Green
venki83k
venki83k
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 158
Hi

I am executing this against database i got above error .

Basically using this to track db growth of all database on a server.colud you please suggest anybody on this.


insert all_dbs_file_size(dbs_name,rec_model,dbf_size_in_MB,log_size_in_mb)
select
d.name
,d.recovery_model_desc
,convert(decimal(18,2),(sum(size)*8)/1024.0) as dbf_size_in_mb
,(select (size*8)/1024.0 from sys.sysaltfiles where dbid=saf.dbid and groupid=0) as log_size_in_mb
from sys.sysaltfiles saf
join sys.databases d on saf.dbid=d.database_id
where groupid>0
group by dbid,d.name,d.compatibility_level,d.recovery_model_desc



Regards,
Sreen.
Kingston Dhasian
Kingston Dhasian
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3007 Visits: 5016
venki83k (1/8/2013)
Hi

I am executing this against database i got above error .

Basically using this to track db growth of all database on a server.colud you please suggest anybody on this.


insert all_dbs_file_size(dbs_name,rec_model,dbf_size_in_MB,log_size_in_mb)
select
d.name
,d.recovery_model_desc
,convert(decimal(18,2),(sum(size)*8)/1024.0) as dbf_size_in_mb
,(select (size*8)/1024.0 from sys.sysaltfiles where dbid=saf.dbid and groupid=0) as log_size_in_mb
from sys.sysaltfiles saf
join sys.databases d on saf.dbid=d.database_id
where groupid>0
group by dbid,d.name,d.compatibility_level,d.recovery_model_desc



Regards,
Sreen.


Don't hijack threads of other posters, always create a new thread for your request

Anyways, here is the solution for your problem

INSERT   all_dbs_file_size( dbs_name, rec_model, dbf_size_in_MB, log_size_in_mb )
SELECT D.name, D.recovery_model_desc,
CONVERT(DECIMAL(18,2), SUM( CASE WHEN S.groupid = 1 THEN S.size ELSE 0 END ) * 8 / 1024.00 ) AS dbf_size_in_mb,
CONVERT(DECIMAL(18,2), SUM( CASE WHEN S.groupid = 0 THEN S.size ELSE 0 END ) * 8 / 1024.00 ) AS log_size_in_mb
FROM sys.sysaltfiles AS S
INNER JOIN sys.databases AS D ON S.dbid = D.database_id
GROUP BY D.name, D.recovery_model_desc




Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search