I want to insert dummy data to my table let's say 10000 records using loop or whatever. Table definition as follows:
ID (PK & AI) | ArticelNumber (varchar unique) | CreateDate (Datetime)
I want to insert dummy data to my table let's say 10000 records using loop or whatever. Table definition as follows:
ID (PK & AI) | ArticelNumber (varchar unique) | CreateDate (Datetime)
I think below will meet your criteria, ask in comments if any questions:
-- create table
create table #tmp
(ID int primary key,
ArticeNumber nvarchar(50),
CreateDate datetime)
go
-- loop with insert
declare @incr int = 1
while (@incr < 10001)
begin
-- use "getdate() - @incr" as below if you want to have diffrent dates or just getdate() if not
insert into #tmp
select @incr, newid(), getdate() - @incr
-- second option to insert below
-- insert into #tmp
-- select @incr, 'ArticleNo: ' + cast(@incr as nvarchar), getdate() - @incr
-- increment int
set @incr = @incr + 1
end
go
-- select your date
select * from #tmp
-- below is just to prove ArticleNumbert is unique
select distinct ArticeNumber from #tmp
-- drop table if necessary
drop table #tmp
Ok, if your table has id identity, and all you need is to insert unique ArticleNumber and current date you can use top 10000 from any table containing at least 10000 rows, or this way:
insert into yourTble(ArticleNumber, CreateDate)
select top 10000 newid(), getdate()
from sys.all_columns cross join sys.all_columns c1;
Or just use GO 10000 e.g.
INSERT INTO <yourtable>(DatetimeCol, varcharCol, IntegerCol,...)
VALUES(sysdatetime(),'<yourtext>',<yourInt>,...);
GO 10000
You can use http://generatedata.com/ website
It's easy to understand how it works,and you can put the criteria you want
You can insert default values with that insert query;
INSERT INTO table DEFAULT VALUES