Forum Discussion
EMARIN91
Jun 15, 2019Copper Contributor
Update a field of a SQL table using a trigger from another table-field (PK)
Good afternoon community,
I have the following tables: dbo.RegistroGeneral: IdInpeccion (PK) int, IdEquipo int, IdEmpleado int, FechaFin datetime, FechaInicio datetime dbo.RegistroPasos:...
shah_chandra
Jun 17, 2019Copper Contributor
You could create a trigger on first table as follows, and it could work
CREATE TRIGGER TriggerName_Insert ON Table1
FOR INSERT
AS
DECLARE @newid as int ;-- gets the column information from the first table
SET @newid = (select i.ColumnName1 from inserted i)
INSERT INTO Table2(ColumnName1) values (@newid)
For more about triggers, you can have a look on below link. He explains all the trigger types
https://www.codeproject.com/Articles/25600/Triggers-SQL-Server
Have a great day :)