question

RBarryYoung avatar image
RBarryYoung asked

Identity Insert Statement

I have participated in several of the StackOverflow sites, and one of the things that I have noticed is that there is a real "bootstrap" problem in the beginning. There really needs to be a certain minimum number of active members with a minimum number of points before it really starts to work. In the interests of addressing this, (and unless the powers that be object) I will be posting challenge questions based on some of the older SqlServerCentral Questions Of The Day. The first answer which is correct will be marked as accepted (15 points). For the most part I will not be presenting the questions as multiple choice, as they originally were.


Identity Insert:

We have a table and it has just one column that the identity property of that column is set to ON, we need a query to insert some records in that, which of the following will work:

We have the following table:

CREATE TABLE TestID( ID int Identity(1,1))

What is the INSERT statement to insert records into this table?

insertidentitychallengeqotd
10 |1200

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

Matt Whitfield avatar image
Matt Whitfield answered
INSERT INTO TestID DEFAULT VALUES
2 comments
10 |1200

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

RBarryYoung avatar image RBarryYoung commented ·
Great Job, Matt! You've almost got enough points now to down-vote things (though I would recommend against that during this break-in period for the site, except the most awful stuff, spam, ads, etc.)
1 Like 1 ·
Matt Whitfield avatar image Matt Whitfield ♦♦ commented ·
I thoroughly agree - I think it's going to be down to some of the SSC residents to build the site up, looking forward to it being more active :)
1 Like 1 ·
David Lean avatar image
David Lean answered
May be worth mentioning that from SQL Server Management Studio (SSMS) you can add an integer after the GO command that inticates how many times to execute the batch. eg: INSERT INTO TestID DEFAULT VALUES GO 100 Will enter 100 rows into the table. No need to create a loop. And if you use Random numbers, GETDATE(), joins or similar functions you can rapidly build halfway decent load tables.
10 |1200

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

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.