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 6356571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:59:20+00:00 2026-05-24T22:59:20+00:00

I’m working on a database where I retrieve the ID of my record after

  • 0

I’m working on a database where I retrieve the ID of my record after I’ve added it by saving and retrieving a known GUID. My application runs on both SQL Server and Oracle, so I can’t use @@IDENTITY*.

Say for example, I add a new address:

ID (identity column in SQL Server;sequenced/trigger column in Oracle)
... address data... (street, town, postcode, etc.)
GUID

I get the ID back by doing the following:

1. INSERT INTO ADDRESS (... address details, GUID = {some new GUID value})
2. SELECT ID FROM ADDRESS WHERE GUID = {my GUID value}
3. UPDATE ADDRESS SET GUID = NULL WHERE GUID = {my GUID value}

At part 1, I’m adding the address details and setting the GUID value in the database; at part 2, I’m getting my ID back and at part 3, I’m removing the GUID value from the database (to avoid the very unlikely event of a duplicate GUID).

When I look at the SQL Server 2008 Estimated Execution Plan for the third bit, it shows the following path if I have no index on the GUID column:

Image shows the estimated execution plan where there's no index on the GUID column

and the following path if I have an index on the GUID column:

Image shows the estimated execution plan where there's an index on the GUID column

My question is: I realise that the scan shown in the first image is not as good as the seek shown in the second image, but would the fact that the GUID column is essentially empty 99.999% of the time mean that I shouldn’t index the field, because it would be fragmented all the time and would waste resources? Or would the index still help because it would easily show me where my one-and-only GUID is that I just added, rather than having to do a whole scan for it?

In summary: Given the fact that the GUIDs are added and then immediately removed, is there any point in indexing the GUID column?

*In fact, the design is not my own, so I’m unable to use a different method; however, you should see that the design of my particular database does not affect my overall question.

  • 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-05-24T22:59:21+00:00Added an answer on May 24, 2026 at 10:59 pm

    Yes, you absolutely need to index your column for what you’re doing. Use a filtered index in SQL Server (not sure what is the Oracle equivalent):

    create index AddressGuid on ADDRESS(GUID) where GUID is not NULL;
    

    But there is abetter way: use OUTPUT/RETURNING clause of INSERT. Both SQL Server and Oracle supports it (each its own flavour) and you no longer need the GUID workaround.

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

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a view passing on information from a database: def serve_article(request, id): served_article
I am writing an app with both english and french support. The app requests
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.