Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Updating an INT column with a sequential value?

 
   Database Forums (Home) -> Sybase RSS
Next:  XMLDB on9i  
Author Message
woooopa

External


Since: Dec 07, 2004
Posts: 1



(Msg. 1) Posted: Tue Dec 07, 2004 9:19 am
Post subject: Updating an INT column with a sequential value?
Archived from groups: comp>databases>sybase (more info?)

I'm trying to assign a destinct value to 4,742 rows. How would I
construct a script to accomplish this starting with a value of 1000?
Thank you.

 >> Stay informed about: Updating an INT column with a sequential value? 
Back to top
Login to vote
saradba

External


Since: Dec 07, 2004
Posts: 31



(Msg. 2) Posted: Tue Dec 07, 2004 10:32 am
Post subject: Re: Updating an INT column with a sequential value? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi There,

Here's a trick ... given any table with primary key PK, one can
generate a sequential number using the following:

Consider: Table t1 (int1 int, char1 char(01), int2 int)
Primary Key on int1

insert t1 select 10,"A",0
insert t1 select 11,"B",0
insert t1 select 12,"C",0

select a.int1, c1=1000+count(*)
into t2
from t1 a, t1 b
where a.int1 >= b.int1
group by a.int1

update t1 set a.int2 = b.c1
from t1 a, t2 b
where a.int1 = b.int1

select * from t1

int1 char1 int2
----------- ----- -----------
10 A 1001
11 B 1002
12 C 1003

(3 rows affected)

I think this is what you want to do outside of using an identity column
of course ...

I'm not sure how this scales to very large tables ... good luck!!

Cheers,

Sara ...

woooopa wrote:
 > I'm trying to assign a destinct value to 4,742 rows. How would I
 > construct a script to accomplish this starting with a value of 1000?
 > Thank you.

 >> Stay informed about: Updating an INT column with a sequential value? 
Back to top
Login to vote
Rob Verschoor

External


Since: Aug 21, 2003
Posts: 114



(Msg. 3) Posted: Tue Dec 07, 2004 5:40 pm
Post subject: Re: Updating an INT column with a sequential value? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Add an identity column to the table, numbering the columns from 1 to 4742.
Then add another column (type int) to the table and update this last column
to be the value of the identity column plus 999.

HTH,

Rob
-------------------------------------------------------------
Rob Verschoor

Certified Sybase Professional DBA for ASE 12.5/12.0/11.5/11.0
and Replication Server 12.5 / TeamSybase

Author of Sybase books (order online at <a rel="nofollow" style='text-decoration: none;' href="http://www.sypron.nl/shop" target="_blank">www.sypron.nl/shop</a>):
"Tips, Tricks & Recipes for Sybase ASE"
"The Complete Sybase Replication Server Quick Reference Guide"
"The Complete Sybase ASE Quick Reference Guide"

mailto:rob@YOUR.SPAM.sypron.nl.NOT.FOR.ME
<a rel="nofollow" style='text-decoration: none;' href="http://www.sypron.nl" target="_blank">http://www.sypron.nl</a>
Sypron B.V., P.O.Box 10695, 2501HR Den Haag, The Netherlands
-------------------------------------------------------------

"woooopa" wrote in message

 > I'm trying to assign a destinct value to 4,742 rows. How would I
 > construct a script to accomplish this starting with a value of 1000?
 > Thank you.
 >
 >> Stay informed about: Updating an INT column with a sequential value? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
ASE 15.0.2 column encryption. - We are running ASE 15.0.2 on AIX, with column encryption option. Encrypted few columns, works fine. user wants to encrypt a text column, since ASE does not encrypt text column, we will be modifying text to varchar or char and then encrypt the column. Jus...

type of column - What type of column needs to use that writes and stores big file?

How to retrieve the date part of a DATETIME column via (T-.. - Hi, I'm new to SQL and looking to a way to retrieve the day part of a DATETIME column. By now I'm using CONVERT, which gives me a CHAR. To keep the result sortable, I have to use a format apropriate to that demand. But I'd prefer getting a DATETIME...

Index on Date Column for select today - Im using DBlib from C++. I have a file with a datetime field, and the only way I could thin of selecting rows for today was: sprintf(cmd,"select max(BatchSeqNo) from %s "\ "where convert(char(10),getdate(),1) = "\ ..

Max Rows Per Page, Reserve Page Gap, and Fill Factor - I have been trying to find information on how to try to figure this out without any luck. What is the best way to figure out how to set the following based on the locking schemes? Does everyone just use the defaults, which are zeros? I was reading how....
   Database Forums (Home) -> Sybase All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]