Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

How to Introduce Time Delay Between Two T-SQL Commands? Interview Question of ...

$
0
0

Question:How to Introduce Time Delay Between Two TSQL Commands?


How to Introduce Time Delay Between Two T-SQL Commands?   Interview Question of ...

Answer:Every time when I hear this question, I am very confident this question is from a developer. This is because I have observed quite a lot of time in developer world this question being discussed. There are processes and functions which need to have a time delay between them and the programming language developer knows how to use various delays related time functions to achieve it.

However, it is really not something I see in the database world. Trust me personally I have yet not come across a situation where I would need delay between two commands in the database. There are different ways to achieve the same outputwith a different strategy of code in SQL Server. Anyway, in the interview processes sometimes as a candidate we aremore incline to answer interviewers than argue with them.

Let us see how we can add delay between two T-SQL statement in following example.

In following example, I am adding a 10 second delay between two SELECT statement.

SELECT GETDATE() CurrentTime WAITFOR DELAY '00:00:10' -- 10 Second Delay SELECT GETDATE() CurrentTime

When you execute above script, it gives us following output.


How to Introduce Time Delay Between Two T-SQL Commands?   Interview Question of ...

You can clearly see in the result setthat there are10 second delay between two SELECT statement.

Now here is a question back to you? Have you ever used WAITFOR DELAY function in your business in SQL Server? If yes, would you please leave a comment so we can learn from you.

Here are two blog posts and a video poston the same subject I have written earlier.

Time Delay While Running T-SQL Query WAITFOR Introduction Delay Function WAITFOR clause Delay Execution of Commands Video Delay Command in SQL Server SQL in Sixty Seconds #055

Reference: Pinal Dave ( http://blog.sqlauthority.com )


Viewing all articles
Browse latest Browse all 3160

Latest Images

Trending Articles



Latest Images