Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2012
    Posts
    8

    setting initial value for identity column in sybase ASE 15

    I am working with sybase ASE 15.5 version. I have to create a table with a primary key from one table and an identity column to generate an identity value for the primary key of the main table like this
    select newid = identity(10), id into newtb1 from table1

    And I have to do this for all the source tables. The problem i face here is when I am doing this the identity column is getting generated newly everytime. For newtb1 if the newid column is from 1 to 100, for the next table newtb2 i want the identity column from 101. Is there any way of setting the initial value of the identity column and then do a select?
    Please help me with this.

    Thanks

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,501
    Usually the identity statement takes two parameters. Seed and increment. I am not sure which one is assumed when you supply a value, but I imagine it is the seed. As an alternative, you could try something like
    Code:
    select newid = identity(1) + 100, id into newtb1
    from table1

  3. #3
    Join Date
    Oct 2012
    Posts
    8
    Thanks for the reply.

    Now with this mapping table for the primary key of base table, I need to insert data from the base table to a new table with the primary key as the equivalent identity value created in the mapping table.
    I am forced to do this in batches since the source table is large and in the source table the primary key is of datatype binary(16). Please help me to do this in batches.

    I tried this by setting rowcount and storing the data into a temp table and then copying data from the temp table to the destination table with the primary key replaced by the identity value created in the mapping table.
    But after inserting the first batch how do I get the next batch on what criteria? I tried using the minimum and maximum of primary key, but it dint work since it is of type binary(16).
    Please help me with this.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •