How to use GO Statement in SQL Server To Insert Records in Identity Column - SQL Server / T-SQL Tutorial Part 42

Go is command that is recognized by sqlcmd, osql and SSMS utilities and we use it to terminate batch. GO is not Transact SQL command.

We can use GO [Count] to run the batch the times we want to. To insert records into a table that has only identity column, we can use GO statement with count as well.

USE TestDB
GO

DROP TABLE dbo.CustomerAddress
GO

CREATE TABLE dbo.CustomerAddress (
    FName VARCHAR(100)
    ,LName VARCHAR(100)
    ,HouseNumber INT
    ,StreetName VARCHAR(100)
    ,City VARCHAR(100)
    ,[State] CHAR(2)
    ,IsActive BIT
    )
GO

--Insert the same record ten times by using GO [count]
INSERT INTO dbo.CustomerAddress
VALUES (
    'Aamir'
    ,'Shahzad'
    ,123
    ,'Test Street'
    ,'Charlotte'
    ,'NC'
    ,1
    ) GO 10

CREATE TABLE dbo.CustomerT (id INT identity(1, 1))
GO

--Insert 100 records into table that has only id as identity column by using GO [Count]
INSERT INTO dbo.CustomerT DEFAULT
VALUES GO 100




Video Demo : Use GO Statement in SQL Server To Insert Records in Identity Column