Guest User

Untitled

a guest
Dec 12th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. Create Trigger [dbo].[InsertPersonalInfoTrigger] ON [dbo].[PersonalInfo]
  2. after Insert
  3. as
  4. begin
  5. declare @Name nvarchar(50)
  6. declare @FamilyName nvarchar(50)
  7. declare @FatherName nvarchar(50)
  8. declare @BirthDate nchar(10)
  9. declare @GenderID int
  10. declare @NationalId nvarchar(50)
  11. declare @id int
  12.  
  13.  
  14. select @Name=Max(@Name),@FamilyName=Max(@FamilyName),@FatherName=Max(@FatherName),@BirthDate=Max(@BirthDate)
  15. ,@GenderID=Max(@GenderID),@NationalId=Max(@NationalId),@id=Max(@id)
  16. from Inserted
  17. if(@Name='')
  18. begin
  19. RAISERROR ('Enter the Name',
  20. 16,
  21. 1
  22. );
  23. RollBack
  24. return;
  25. end
  26. declare @LogID int
  27. set @LogID= (select isnull(max(LogID),0) from DBLog) +1
  28.  
  29. declare @ActionDes varchar(2000);
  30. set @ActionDes = 'Insert Into Gender INNER JOIN
  31. PersonalInfo ON Gender.GenderID = PersonalInfo.GenderID INNER JOIN
  32. RegisterationForm ON PersonalInfo.id = RegisterationForm.id(Name,FamilyName,FatherName,BirthDate,GenderID,NationalId,id)
  33. Values("' + @Name + '","' + @FamilyName + '","' + @FatherName + '","' + @BirthDate + '",'+cast(@GenderID as varchar(20))+ ',
  34. "' + @NationalId +'",'+cast(@id as varchar(20))+ ')';
  35. declare @dt datetime;
  36. set @dt=getdate();
  37.  
  38. declare @usr varchar(50);
  39. select @usr =current_user
  40.  
  41. insert into DBLog(LogID,ActionDes,ActionTime,ActionUser)
  42. values (@LogID,@ActionDes,@dt,@usr)
  43. end
  44. Go
Add Comment
Please, Sign In to add comment