What's the exact situation? Is this a one off or something that will happen on a regular basis?
FACT: You can only update one table at a time (you can use views to give the impression that multiple tables are updated at once but we don't need to go there).
Trigger or SP?
A trigger is essentially a stored procedure that gets fired in response to an event (insert/update/detele).
But if you use a stored procedure you will need to 'manually' call it after updating one of the tables.
Just use whatever method you're more comfortable with.
How do you do it?
PROCEDURE:
You'll need something like this...
- Code: Select all
CREATE PROCEDURE dbo.UpdateTables(@value nvarchar(100)) AS
BEGIN
UPDATE TABLE1 SET field1 = @value
UPDATE TABLE2 SET field2 = @value
END
Add parameters and use the WHERE clause to update only certain records...
TRIGGER:
You will need something like...
- Code: Select all
CREATE TRIGGER [TABLE1Trigger] ON [dbo].[TABLE1]
FOR INSERT, UPDATE, DELETE -- if applicable
AS
UPDATE TABLE2 SET field2 = (SELECT field1 FROM TABLE1)
END
You actually have to use WHERE the clause in this case but you get the idea...
Hope this helps
