Monday, 19 November 2018

MS SQL - Execute Insert Query Every Second

Watch this example on YouTube



1. Table:
/****** Object:  Table [dbo].[DateTable]    Script Date: 2018-11-19 7:31:19 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[DateTable](
    [DateField] [datetime] NULL
) ON [PRIMARY]

GO

2. Insert Query
while(1 = 1)
begin
    begin try
    Insert Into DateTable(DateField) values (GetDate())
    waitfor delay '00:00:01'
    end try
    begin catch
        select 'some error ' + cast(getdate() as varchar)
    end catch
end

3. Check (select query)
select * from DateTable order by DateField desc

1 comment:

  1. That is what I was looking for, thanks!

    ReplyDelete