Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sync 2 tables using triggers

Author  Topic 

vinrena
Starting Member

1 Post

Posted - 2015-03-05 : 11:54:11
Hi, i'm new to sql server triggers.
I have 2 tables (one master and one slave) with a primary on multiple columns. I need to create a trigger on first table in order to syncronize second table.
In which way i could manage an update on multiple rows on a column on primary key?

My tables are:
CREATE TABLE [dbo].[Seasons](
[Entity] [nvarchar](4) NOT NULL,
[Code] [nvarchar](5) NOT NULL,
[Description] [nvarchar](50) NULL,
CONSTRAINT [PK_Seasons] PRIMARY KEY CLUSTERED
(
[Entity] ASC,
[Code] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 10) ON [PRIMARY]
) ON [PRIMARY]


CREATE TABLE [dbo].[Seasons2](
[Entity] [nvarchar](4) NOT NULL,
[Code] [nvarchar](5) NOT NULL,
[Description] [nvarchar](50) NULL,
CONSTRAINT [PK_Seasons2] PRIMARY KEY CLUSTERED
(
[Entity] ASC,
[Code] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 10) ON [PRIMARY]
) ON [PRIMARY]



INSERT INTO [Seasons] VALUES ('XX','11','Test')
INSERT INTO [Seasons] VALUES ('XX','22','Test')
INSERT INTO [Seasons] VALUES ('XX','33','Test')



UPDATE [Seasons] SET Entity = 'YY'


In the worst case, could i iterate over inserted and deleted tables? These tables are in the same order?

Thank you very much!





   

- Advertisement -