Insert multiple records at once in SQL Server table.

Requirement: To create an Employee table and insert one thousand test records at once.

Code:
CREATE TABLE Employee (Eid int, EName varchar(100),Esal int)
DECLARE @i int=0
WHILE (@i<1000)
BEGIN
INSERT INTO Employee VALUES (@i,'Emp'+convert(varchar,@i),100+@i)
SET @i=@i+1
END

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s