Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can I do this in a stored procedure (multiple cmds)
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00833437
Message ID:
00833444
Views:
24
This message has been marked as the solution to the initial question of the thread.
Hi Kirk,

It's fine to update more than one table in the sproc but I would make it one transaction to so either both of the tables are updateted or none.
BEGIN TRANSACTION
Update coSuper set isActive=0 where coSuperID=@tiCardID
...
Update coSuper2 set isActive=0 where coSuperID=@tiCardID
...
COMMIT  TRANSACTION
You may also consider using UPDATE trigger on coSuper that will update coSuper2 table's isActive field if it changes to 0 in coSuper table. This way your data will be consistent regardless how or from where isActive was changed to 0 in coSupe table.

>When a user deletes a master record, I want to delete the children in the children table (coSuper and coSuper2), I don't actually delete them, but change a flag (isactive) from true to false. Just wondering if this is ok in a stored procedure:
>
>
>CREATE PROCEDURE ct_DelPrefCard
>@tiCardID int
>
>as
>SET NOCOUNT ON
>begin
>--Delete the actual card
>Update coSuper set isActive=0 where coSuperID=@tiCardID
>
>--Delete the child records
>Update coSuper2 set isActive=0 where coSuperID=@tiCardID
>
>--Delete our linked listed items in the coCardAssign table
>--delete from coCardAssign where coSuperID = @tiCardID
>
>set nocount off
>
>end
>
>
>Thanks
>Kirk
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform