K
K
Kjudy2022-03-23 10:03:42
SQL Server
Kjudy, 2022-03-23 10:03:42

Auto insert timestamp value ms sql how to do?

Good day, I apologize immediately for stupid questions)
The bottom line is that you need to create a stored procedure so that when data is entered into the database, the timestamp column is automatically filled with the current date and time ...

USE [arch_to_report]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create procedure AddValue
    (@Time_val datetime,
     @Val1 real,
   @Val2 real,
   @Val3 real,
   @Val4 real)
     as
begin
    insert [dbo].[Values] values (@Time_val, @Val1, @Val2, @Val3, @Val4);
end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2022-03-23
@Kjudy

ALTER TABLE [dbo].[Values] ADD CONSTRAINT DF_T1_timestamp DEFAULT GETDATE() FOR [timestamp]

This must be done once. Do not change the procedure.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question