sql – Stored Procedure for entering log data

Question:

I need to create a Stored Procedure in my SQL Server database. The purpose of this Stored Procedure is to record data in a Log table, which has three fields: date, time, login ID.

Date and time would be from login time, while Login ID comes from a login table. The site will already have the time to call this Stored Procedure at login.

The big question is what code I put in Stored Procedure, since I hardly work with it in SQL Server. Who can help in this?

Answer:

Basically you just need the following.

CREATE Proc [dbo].[sp_LogUsuario_Update]
  @IdUsuario int,
  @DtInclusao int
  -- se precisa de mais campo adicione aqui.
as
begin
  Set Xact_Abort on
  Set Nocount on
  Begin Tran

  begin
     -- informe os campos que você que inseri na sua tabela
    Insert into tb_LogUsuario( IdUsuario,  DtInclusao) values
     ( 
        --- aqui você passa seus campos caso a data seja a hora local user o GETDATE() , o tipo de campo  da tabela tem 
        -- que ser DAteTime
        @IdUsuario, @DtInclusao 
     )

  end

  Commit
end
GO

Change what is necessary according to your need.

Scroll to Top