Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8658629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:48:54+00:00 2026-06-12T15:48:54+00:00

I have a table say scope_test as follows: create table scope_test ( id int

  • 0

I have a table say scope_test as follows:

create table scope_test
(
id int identity(1,1),
val varchar(100)
)

Now when i insert a row in this table and select the scope identity through 2 different sql statements, i get to see a difference in performance of the 2 statements:

insert into scope_test values('abcd')
select scope_identity() -- statement 1
select scope_identity() from scope_test -- statement 2

statement 1 is faster than statement 2 according to the execution plan:

enter image description here

I am curios to know :
1. why is this difference in performance , and
2. Is it safe to use scope identity() as used in statement 1 i.e. without the table name ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:48:56+00:00Added an answer on June 12, 2026 at 3:48 pm

    The difference in performance is simply because you are doing different things. The second use of scope_identity doesn’t just get the last identity, it gets all records in the table and selects the value from scope_identity() for each record in the table. You will just get the value from scope_identity() once for each record that exists in the table.

    So, the second use of scope_identity() is simply pointless, it will return the same value one or more times (or zero times if the table used in the query would be empty). The value of scope_identity()is not at all related to the table that you use in the query, i.e. if you insert records in different tables you can’t use it to get the last id inserted in a specific table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a table like so: CREATE TABLE big_table (UUID varchar(32) not null,
Let's say I have a table my_table(id int identity(1,1) not null primary key, data
Lets say I have table named Place with columns: placeId int not null auto_increment,
Lets say I have table with ID int, VALUE string: ID | VALUE 1
Let's say I have this table: ID Score 1 345 2 5 3 76
Let's say I have a table with 100 product reviews. Each review has an
Let's say I have this unique index on a table: add_index :events, [:venue_id, :act_id,
Let's say I have a table like this: name | score_a | score_b -----+---------+--------
Say I have a table like ID, NAME, SCORE. Now normally, to get the
Let's say my table structure looks something like this: CREATE TABLE [dbo].[table1] ( [id]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.