-2

I have created a table called table1 which has a column called column1.

How can I populate column1 with (e.g.) 1000 rows in which each row has a unique number going from 1 to 1000? The first row has number 1, the second 2, the third has 3, etc.

Luc M
  • 16,630
  • 26
  • 74
  • 89
dll
  • 161
  • 2
  • 21

1 Answers1

1

You can do it like this

DECLARE @i INT = 1
WHILE @i <= 1000
BEGIN
  INSERT INTO table1 (column1) VALUES (@i)
  SET @i = @i + 1
END
SQLChao
  • 7,709
  • 1
  • 17
  • 32
  • Thanks but, the code does not specify column1, Can you explain why there is do not need to specify that we want to increment column1? What if I have multiple columns? – dll Sep 27 '17 at 14:36
  • @dll I edited it to specify the column. Sorry I took your question literally as you had a table with a single column in it. – SQLChao Sep 27 '17 at 14:37
  • No problem, thanks it works ! – dll Sep 27 '17 at 14:48
  • Why use a loop for this? – S3S Sep 27 '17 at 14:52