Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert specific bounded numbers into a column in SQL Server

I want to write a SQL query that inserts incremental numbers that start in specific number (for example 100) and ends at another specific number (for example 3000) into a column of a table in SQL Server, but I don't know how to do this.

For example:
I want to insert 100 to 3000 into categoryID (column) from Category (table)

Thank you very much

like image 911
atabrizi Avatar asked May 12 '12 07:05

atabrizi


Video Answer


1 Answers

DECLARE @id INT
SET @id = 100
WHILE (@id <= 300)
BEGIN
    insert into categories (categoryID) values (@id)
    SELECT @id = @id + 1
END
like image 129
juergen d Avatar answered Nov 09 '22 17:11

juergen d