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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:34:19+00:00 2026-06-15T16:34:19+00:00

Apply this sql script: create table software ( id bigint not null, name varchar(255),

  • 0

Apply this sql script:

create table software (
  id                        bigint not null,
  name                      varchar(255),
  description               varchar(255),
  constraint pk_software primary key (id))
;

create sequence software_seq;

Then this one:

alter sequence software_seq start with 1000;;

insert into software (id, name, description) values (  1, 'Soft1', 'Description1');

Then when insert new software programatically (from java), got new software with id = 24

Why not with 1001? Since ‘alter sequence software_seq start with 1000;’

  • 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-15T16:34:20+00:00Added an answer on June 15, 2026 at 4:34 pm

    You have a few things wrong here.

    First of all, just creating a sequence with a particular name doesn’t attach it to the table and column that you want using it. You need to change software.id to use software_seq for default values:

    alter table software alter column id set default nextval('software_seq');
    

    and you’ll want to change the sequence’s ownership too (unless of course you’re using the sequence in other places):

    OWNED BY table_name.column_name
    OWNED BY NONE

    The OWNED BY option causes the sequence to be associated with a specific table column, such that if that column (or its whole table) is dropped, the sequence will be automatically dropped as well. If specified, this association replaces any previously specified association for the sequence. The specified table must have the same owner and be in the same schema as the sequence. Specifying OWNED BY NONE removes any existing association, making the sequence “free-standing”.

    So you should:

    alter sequence software_seq owned by software.id;
    

    Then when inserting, you’d either leave out the id:

    insert into software (name, description) values ('...', '...');
    

    or specify DEFAULT:

    insert into software (id, name, description) values (default, '...', '...');
    

    Your other problem is that start with doesn’t do what you think it does:

    start

    The optional clause START WITH start changes the recorded start value of the sequence. This has no effect on the current sequence value; it simply sets the value that future ALTER SEQUENCE RESTART commands will use.

    If you want the sequence to start at 1000 then you can:

    alter sequence software_seq restart with 1000;
    

    Alternatively, you could use setval:

    select setval('software_seq', 1000);
    

    Of course, you could also use bigserial:

    The data types smallserial, serial and bigserial are not true types, but merely a notational convenience for creating unique identifier columns (similar to the AUTO_INCREMENT property supported by some other databases). In the current implementation, specifying:

    CREATE TABLE tablename (
        colname SERIAL
    );
    

    is equivalent to specifying:

    CREATE SEQUENCE tablename_colname_seq;
    CREATE TABLE tablename (
        colname integer NOT NULL DEFAULT nextval('tablename_colname_seq')
    );
    ALTER SEQUENCE tablename_colname_seq OWNED BY tablename.colname;
    

    So using bigserial as the id column type would set up all the sequence stuff for you. Then you’d set the starting value as before using alter sequence or setval.

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

Sidebar

Related Questions

if i apply a sql query statement to this table select * from context.tablename,
Imagine the following tables: create table boxes( id int, name text, ...); create table
Is there anyway to apply this method from Chris Coyier to mobile phones: http://css-tricks.com/full-browser-width-bars/
I managed to apply this excellent example to my needs: http://code.google.com/p/galleriffic/issues/attachmentText?id=76&aid=-3045121742886940548&name=example-2.html&token=4nlvmgAfVpc5whcXC9UEqHZaSz0%3A1339257750721 With a small
when i apply this styles to option element: border-color: #8A8A8A #E5E5E5 #E5E5E5 #8A8A8A; border-style:
im trying to apply this JSON code to my Google Map: [ { stylers:
Does anyone knows why after I apply this algorithm in c++ to reduce the
Many times I see statements like following Y.CustomApp.superclass.render.apply(this, arguments); I know how apply works.
I'd like a hint on how to apply this function: dti xs = (map
I can't figure out how can I apply this kind of effect to the

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.