If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > setting initial value for identity column in sybase ASE 15

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
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
Reply With Quote
  #2 (permalink)  
Old
Wage drone 24601
 
Join Date: Jan 2003
Location: Massachusetts
Posts: 5,446
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
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
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.
Reply With Quote
Reply

Tags
identity col initial val

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On