Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Create Trigger [dbo].[InsertPersonalInfoTrigger] ON [dbo].[PersonalInfo]
- after Insert
- as
- begin
- declare @Name nvarchar(50)
- declare @FamilyName nvarchar(50)
- declare @FatherName nvarchar(50)
- declare @BirthDate nchar(10)
- declare @GenderID int
- declare @NationalId nvarchar(50)
- declare @id int
- select @Name=Max(@Name),@FamilyName=Max(@FamilyName),@FatherName=Max(@FatherName),@BirthDate=Max(@BirthDate)
- ,@GenderID=Max(@GenderID),@NationalId=Max(@NationalId),@id=Max(@id)
- from Inserted
- if(@Name='')
- begin
- RAISERROR ('Enter the Name',
- 16,
- 1
- );
- RollBack
- return;
- end
- declare @LogID int
- set @LogID= (select isnull(max(LogID),0) from DBLog) +1
- declare @ActionDes varchar(2000);
- set @ActionDes = 'Insert Into Gender INNER JOIN
- PersonalInfo ON Gender.GenderID = PersonalInfo.GenderID INNER JOIN
- RegisterationForm ON PersonalInfo.id = RegisterationForm.id(Name,FamilyName,FatherName,BirthDate,GenderID,NationalId,id)
- Values("' + @Name + '","' + @FamilyName + '","' + @FatherName + '","' + @BirthDate + '",'+cast(@GenderID as varchar(20))+ ',
- "' + @NationalId +'",'+cast(@id as varchar(20))+ ')';
- declare @dt datetime;
- set @dt=getdate();
- declare @usr varchar(50);
- select @usr =current_user
- insert into DBLog(LogID,ActionDes,ActionTime,ActionUser)
- values (@LogID,@ActionDes,@dt,@usr)
- end
- Go
Add Comment
Please, Sign In to add comment