forum

Home / DeveloperSection / Forums / How to using triggers in SQL Server to keep a history

How to using triggers in SQL Server to keep a history

Sachin Singh215624-Feb-2016

Hi Everyone,

I want to maintain a history of Student table. If any student are concurrent any update or remove in any columns  then their records will be automatically save in StudentHistory table . Here, we will given a Student table script i.e. below:

 

USE [NewUniversity]
GO
/****** Object:  Table

[dbo].[Student]    Script Date: 2/25/2016

12:04:50 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Student](
[StudentID] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [nvarchar](50) NOT NULL,
[LastName] [nvarchar](50) NOT NULL,
[EnrollmentDate] [datetime] NULL,
 CONSTRAINT

[PK_dbo.Student] PRIMARY KEY CLUSTERED [StudentID]

ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,

IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

Please can anyone give me a complete code of triggers on Student Table.

Thank you.

 


Can you answer this question?


Answer

1 Answers

Liked By