In a project test, we might use batch-generated data to test the program's performance.
Here is a question I encountered, because we bulk generated data is almost instantaneous, so the getdate () function is basically the same time, and we ask to generate each data time is different, then how to solve this problem?
Search the Internet a lot, here I use the cursor +waitfor to deal with:
First of all, the downstream target, because the individual is also using the cursor, but also not in-depth study.
So what is a cursor for? In general, we use cursors to process the resulting set of queries (modified, new ...). )。
The cursor definitions in T-SQL are as follows in MSDN:
DECLARE cursor_name cursor [LOCAL | GLOBAL]
[Forward_only | SCROLL]
[STATIC | KEYSET | DYNAMIC | Fast_forward]
[Read_Only | Scroll_locks | Optimistic]
[Type_warning]
For select_statement
[For UPDATE [of column_name [,... N]]
[;]
Simple definition of cursor: DECLARE CURSOR name cursor for result set
Open cursor: Open cursor name
Read down cursor: FETCH NEXT from cursor name into receive variable from data read from result set
Close cursor: Close cursor name
Release cursor: DEALLOCATE cursor name
Because we want to iterate over the result set using cursors, we have to introduce a global variable @ @Fetch_Status
The @ @FETCH_STATUS returns the state of the last cursor executed by the FETCH statement, not the state of any cursors currently open for the connection.
The return value describes the 0 FETCH statement success. The -1 FETCH statement failed or the row is not in the result set. -2 rows that were fetched do not exist
Here are just some simple ways to use cursors.
Let's discuss how to use latency in the database.
WAITFOR DELAY ' 00:00:01 '--executes the print statement after one second
print ' I was delayed execution '
WAITFOR DELAY ' 00:00:00.010 '--10 milliseconds after execution of print statement
print ' I am deferred execution '
waitfor time ' 10:00:00 '--10 point Execution Print statement
print ' I am deferred execution '
SQL Server cursor + deferred execution introduction