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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:47:09+00:00 2026-05-19T13:47:09+00:00

So I’ve been digging around on the net all afternoon to find the answer

  • 0

So I’ve been digging around on the net all afternoon to find the answer to this. I have a table that looks like so:

CREATE TABLE ldap_domains (
    domain varchar(128) NOT NULL,
    name varchar(16) NOT NULL,
    description varchar(32) NOT NULL
)

ALTER TABLE ldap_domains
ADD CONSTRAINT pk_domain PRIMARY KEY (domain);

INSERT INTO ldap_domains VALUES ('test', 'test', 'test');
INSERT INTO ldap_domains VALUES ('test1', 'test', 'test');
INSERT INTO ldap_domains VALUES ('test2', 'test', 'test');
INSERT INTO ldap_domains VALUES ('test3', 'test', 'test');

I need to modify this table so that a new column becomes the primary key. As part of this I need to update the new column with unique values before the constraint is applied. This looks like so:

ALTER TABLE ldap_domains
DROP CONSTRAINT pk_domain;

ALTER TABLE ldap_domains
ADD id int;

DECLARE @key int
SET @key = 0
UPDATE ldap_domains SET @key = id = @key + 1;

ALTER TABLE ldap_domains
ALTER COLUMN id int NOT NULL;

ALTER TABLE ldap_domains
ADD CONSTRAINT pk_id PRIMARY KEY (id);

This works as expected with SQLServer, however, I need this to work for Oracle as well. Essentially the section Oracle doesn’t like is:

DECLARE @key int
SET @key = 0
UPDATE ldap_domains SET @key = id = @key + 1;

Can anyone enlighten me?

  • 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-19T13:47:10+00:00Added an answer on May 19, 2026 at 1:47 pm

    It appears that what you’re trying to do is initially set each row to have a different ID. The preferred way to do this in Oracle is to use a sequence:

    CREATE SEQUENCE seq_ldap_domains START WITH 0;
    
    UPDATE ldap_domains SET id = seq_ldap_domains.nextval;
    

    This will not guarantee that the inserted values are sequential (though, in this case, they likely will be), if that’s relevant.

    Since it is not likely that you will have any other processes updating the field at the same time, it’s probably safe to cheat a little and use something like this, if you really don’t want to create a sequence:

    UPDATE ldap_domains SET id = rownum-1;
    

    As far as I know, you can’t simultaneously read and set an environment variable on a per-row basis in Oracle.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I have two tables with like below codes: Table: Accounts id | username |
I have a jquery bug and I've been looking for hours now, I can't
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.