question

Jenmar22 avatar image
Jenmar22 asked

Insert Statement Syntax

I am learning SQL Server, relatively new. I am trying to insert values under a column named ProductQuantity. I got the first value for the first row in for/of 150. I honestly don't know how I did it since I am unable to repeat it for the next 5 rows for the same column. I used the following INSERT STATEMENT (or so I thought); INSERT INTO dbo.Products (ProductQuantity) VALUES ('150'); GO Would anyone have any suggestions for the correct syntax that would allow me to add a value for the next 5 remaining rows for this column?
syntax
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered
One way to do this is use the GO statement, such as INSERT INTO dbo.Products (ProductQuantity) VALUES ('150'); GO 5 or you could simply repeat the statement 5 times: INSERT INTO dbo.Products (ProductQuantity) VALUES ('150'); INSERT INTO dbo.Products (ProductQuantity) VALUES ('150'); INSERT INTO dbo.Products (ProductQuantity) VALUES ('150'); INSERT INTO dbo.Products (ProductQuantity) VALUES ('150'); INSERT INTO dbo.Products (ProductQuantity) VALUES ('150');
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeff Moden avatar image Jeff Moden commented ·
You'd use a WHILE loop for this? Try it with a million rows and see how long it takes. ;-)
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.