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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Trigger how to?

Author  Topic 

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2013-05-30 : 05:21:00
Hi,

I have a table as follows;

CREATE TABLE [dbo].[A](
[MatchID] [nvarchar](100) NULL,
[MatchCode] [nvarchar](100) NULL,
[SpecialEventCode] [nvarchar](100) NULL,
[IncidentID] [nvarchar](100) NULL,
[Team] [nvarchar](10) NULL,
[Minute] [nvarchar](10) NULL,
[Score] [nvarchar](50) NULL,
[deleteInfo] [nvarchar](10) NULL,
[Player] [nvarchar](100) NULL
) ON [PRIMARY]


I would like to write a trigger and everytime a record is inserted into this table, I want this trigger to insert this new record into another table B.


CREATE TABLE [dbo].[B](
[MatchID] [nvarchar](100) NULL,
[MatchCode] [nvarchar](100) NULL,
[SpecialEventCode] [nvarchar](100) NULL,
[IncidentID] [nvarchar](100) NULL,
[Team] [nvarchar](10) NULL,
[Minute] [nvarchar](10) NULL,
[Score] [nvarchar](50) NULL,
[deleteInfo] [nvarchar](10) NULL,
[Player] [nvarchar](100) NULL
) ON [PRIMARY]


Best Regards.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-30 : 05:28:04
[code]
CREATE TRIGGER YourriggerName
ON dbo.A
AFTER INSERT
AS
BEGIN
INSERT dbo.B
SELECT *
FROM INSERTED
END
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -