Quantcast
Channel: Welcome To TechBrothersIT
Viewing all articles
Browse latest Browse all 2011

How to use GO Statement in SQL Server To Insert Records in Identity Column - TSQL Tutorial

$
0
0
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 Integer,
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


Viewing all articles
Browse latest Browse all 2011

Trending Articles