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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:02:12+00:00 2026-05-22T20:02:12+00:00

SQL SERVER, I’m working with a table that uses a guid for the key

  • 0

SQL SERVER, I’m working with a table that uses a guid for the key instead of an int but for the integration I’m working on, I need it to be an int. So, I want to write something that will create an ID column if it doesn’t exist and populate it with the next highest ID. I’m not really sure how to do this though. Does anyone have code that does this?

i’ve tried this but the update doesn’t work because they’re null

IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_NAME = 'c_Product'AND COLUMN_NAME = 'ProductId')
BEGIN
ALTER TABLE c_Product ADD ProductId INT
END
UPDATE c_Product SET ProductId = (SELECT Max(ProductId) + 1 END FROM c_Product)
  • 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-22T20:02:13+00:00Added an answer on May 22, 2026 at 8:02 pm

    Am I being dense here. Are you not just wanting to do:

    IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS 
    WHERE TABLE_NAME = 'c_Product'AND COLUMN_NAME = 'ProductId')
    BEGIN
        ALTER TABLE c_Product ADD ProductId INT IDENTITY(1,1) not null
    END
    

    Which will assign identity values for all existing rows, and then provide new numbers as new rows are inserted.

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

Sidebar

Related Questions

Sql Server Management Studio 2008 is not scripting table permissions even when I select
SQL Server procedure can return result sets. I have a table emp(emp__id, emp__name, ...)
SQL Server 2005. I'm adding Foreign Key constraints to the database of an application
SQL Server Version 2000. We've a bunch of desktops talking to MSSQL Server. When
SQL Server 2000 Standard, Windows 2003 My coworker removed 'BUILTIN\Administrators' group from SQL Server
SQL Server 2000 doesn't seem to support the xml based .xlsx file types. Besides
SQL Server 2005/2008 Express edition has the limitation of 4 GB per database. As
SQL Server profiler is great for profiling SQL Server performance for web apps. However,
SQL Server (2005/2008) Each of the below statements have the same result. Does anyone
SQL Server 2000: Is there a way to find out server memory / CPU

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.