Introduction
I hope you are aware of this SQL Server feature already, but I am just sharing it for those who don't know one more hidden feature. What is the hidden thing in "GO
" Statement.
Background
Suppose in some situation, you want to repeat a particular SQL statement block number of times, then in such situation, the "GO
" statement will help you.
Using the Code
Suppose I have a debug table with column name "Id
" and I need to Insert 1000
ids, then I can use the following statement:
Go
DECLARE @id AS INT
SELECT @id = COUNT(1) FROM dbo.Debug WITH(NOLOCK)
INSERT INTO dbo.Debug(id) VALUES(@id + 1)
GO 1000
Now when you run this statement, you will get 1000
more rows with different ids. So it is a very nice feature you can enjoy looping with.
Thanks & best regards.
I am Rajat Jaiswal from India. I am working as a Technology specialist in one of the reputed company in India with 12+ years of experience. I am a Microsoft Data Platform MVP & Alibaba Cloud MVP.
I have always had an affinity to learn something new in technology. Database, Web development, Cloud computing are the areas of my interests always.
I have been a regular contributor to technologies with more than 300+ tips. Learning & Sharing is one of my aims always. Writing blogs, delivering sessions, helping on forums is my hobby.