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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:44:44+00:00 2026-05-26T10:44:44+00:00

CREATE TABLE test (id NUMBER PRIMARY KEY, name VARCHAR2(30)); CREATE SEQUENCE test1_sequence START WITH

  • 0
CREATE TABLE test
(id NUMBER PRIMARY KEY,
name VARCHAR2(30));

CREATE SEQUENCE test1_sequence
START WITH 1
INCREMENT BY 1;

INSERT INTO test (id, name) VALUES (test1_sequence.nextval,'Jon');
INSERT INTO test (id, name) VALUES (test1_sequence.nextval,'Hello');
INSERT INTO test (id, name) VALUES (test1_sequence.nextval,'Matt');
INSERT INTO test (id, name) VALUES (test1_sequence.nextval,'Bork');

And suppose if I deleted one record from this table by-

delete from test where id='2';

then If I do select query-

select * from test;

then I get

  ID  Name    
  1    Jon    
  3    Matt
  4    Bork

So If I need to maintain the order of id, like as soon as I delete any data it adjusts the id automatically. So I should be getting the table as

ID  Name    
1    Jon    
2    Matt
3    Bork

Any suggestions how can I do this..

  • 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-26T10:44:45+00:00Added an answer on May 26, 2026 at 10:44 am

    If I remember correctly from articles on Ask Tom website, sequence DOES NOT guarantee that it will produce gap free numbers. So the way you are filling up your table and generating ID’s will never be 100% gap free (even without deleting rows).

    Here’s one of the articles on that subject: http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:4343369880986

    Also keep in mind that you are updating (what seems a) primary key column.

    My suggestion is not to do it. If you need a ordered list of rows, use ROW_NUMBER and leave PK to be a surrogate key without attaching any “application meaning” to it.

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

Sidebar

Related Questions

I have the following table: CREATE TABLE TEST(ID TINYINT NULL, COL1 CHAR(1)) INSERT INTO
I have the following test-code: CREATE TABLE #Foo (Foo int) INSERT INTO #Foo SELECT
i got this Table: CREATE TABLE Test_Table ( old_val VARCHAR2(3), new_val VARCHAR2(3), Updflag NUMBER,
CREATE TABLE TEST_DATE(COL1 VARCHAR2(20),COL2 NUMBER,COL3_DATE DATE,COL4_DATE DATE) / create materialized view TEST_SYS REFRESH FORCE
SQl Server 2005: Option: 1 CREATE TABLE #test (customerid, orderdate, field1 INT, field2 INT,
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have a table defined by the following SQL: CREATE TABLE test ( id
I have a table that's created like this: CREATE TABLE bin_test (id INTEGER PRIMARY
How come the following doesn't work? CREATE FUNCTION Test (@top integer) RETURNS TABLE AS
I have created a test table in MySQL and would like to insert 10

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.