Here's one way of doing it ...
IF OBJECT_ID('Update_table_1','TR') is not null
DROP TRIGGER Update_table_1
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER Update_table_1
ON [table 1] AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
select C.name
into #children
from sysforeignkeys A
join syscolumns B on A.fkeyid=B.id and A.fkey=B.colid
join sysobjects C on A.fkeyid=C.id
where rkeyid = (select id from sysobjects where name = 'table 1')
and fkeyid in (select id from syscolumns where name = 'id')
declare @tname varchar(50)
declare @sql varchar(1024)
declare @id int
declare cur1 cursor for
SELECT name from #children
open cur1
fetch next from cur1 into @tname
while @@FETCH_STATUS = 0
begin
declare curkeys cursor for
select id from inserted
open curkeys
fetch next curkeys into @id
while @@FETCH_STATUS = 0
begin
set @sql = 'update ' + @tname + ' set isLocked = 1 where id = ' + @id
exec(@sql)
fetch next from curkeys into @id
end
close curkeys
deallocate curkeys
fetch next from cur1 into @tname
end
drop table #children
close cur1
deallocate cur1
END
If the child tables have different column names as the foreign keys "pointing" back to the parent then you can find out what those column names are with something similar to this ...
DECLARE @ForId varchar(200)
SET @ForId = (select COLUMN_NAME from INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE CONSTRAINT_NAME LIKE 'FK%' AND TABLE_NAME = @tname)
PRINT @ForId
and then change the dynamic sql to something like
@sql = 'update ' + @tname + ' set isLocked = 1 where ' + @ForId + ' = ' + @id
I didn't amend the sql above as it was easier just to show you how you can get this info.
Note that this will only work if you have a single-column primary key on your tables - now that you know the name of the sql view Google can provide more complex examples if you need them.
Also note that information_schema is a better approach than using sysobjects (or sys.objects for later versions) as it is less likely to change.