Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert 1000 rows at a time

I made Wpf appliaction. I want to test it with 1000 values in grid. I want to check that whether my grid will load 1000 data records fastly or not. So how to write one query to insert more than 1000 records in my database table. can i use for loop.

Insert into db(@names,@email,@password) Values('abc','def','mypassword');

I am using Sql-Server 2012 and ADO.net Connectivity! I want to execute this query in database to generate 1000 rows

EDIT

What if i want to insert unique names?

like image 650
Zoya Sheikh Avatar asked Aug 31 '13 16:08

Zoya Sheikh


People also ask

How can I insert 1000 rows in SQL at a time?

If you just want to generate 1000 rows with random values: ;WITH x AS ( SELECT TOP (1000) n = REPLACE(LEFT(name,32),'_','') FROM sys.

How do I insert 1500 records in SQL?

First query USE CustomerDB; IF OBJECT_ID('Customer', 'U') IS NOT NULL DROP TABLE Customer; CREATE TABLE Customer ( CustomerID int PRIMARY KEY IDENTITY, CustomerName nvarchar(16), ...about 130 more columns... ); INSERT INTO Customer VALUES ('FirstCustomerName', ...), ... 1500 more rows...

How can I add 100 rows in a table in SQL?

You could use the table master. dbo. spt_values : set identity_insert #test1 off; insert into #test1 (test_id) select top (100) row_number() over (order by (select null)) from master.

How do I insert multiple rows at a time in SQL?

INSERT-SELECT-UNION query to insert multiple records Thus, we can use INSERT-SELECT-UNION query to insert data into multiple rows of the table. The SQL UNION query helps to select all the data that has been enclosed by the SELECT query through the INSERT statement.


1 Answers

I create a student table with three column id, student,age. show you this example

declare @id int  select @id = 1 while @id >=1 and @id <= 1000 begin     insert into student values(@id, 'jack' + convert(varchar(5), @id), 12)     select @id = @id + 1 end 

this is the result about the example enter image description here

like image 148
very9527 Avatar answered Sep 22 '22 22:09

very9527