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 > Other > Sequence no's in tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-30-02, 06:19
mwillems mwillems is offline
Registered User
 
Join Date: Sep 2001
Posts: 7
Sequence no's in tables

Hi,
Could someone help me out? I have table with a field that is called unique_id and I need to write some SQL that will populate this field for me with a sequence from 1 to x. I have tried using the tid but unfortunately ingres is very limited with it's use of the tid within SQL. Does anyone have any suggestions about how to do this?

Thanks,

Mark
Reply With Quote
  #2 (permalink)  
Old 09-30-02, 18:30
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
I am not familiar with ingres - but I believe you can do something like the following:

Lets say you have a field called UID - which is your sequential id.

Within your update statement do something like:

update table set uid = (select max(uid) from table) + 1 where ...
Reply With Quote
  #3 (permalink)  
Old 09-30-02, 18:32
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
If that was not helpful - check out the following link:

link
Reply With Quote
  #4 (permalink)  
Old 10-01-02, 03:50
mwillems mwillems is offline
Registered User
 
Join Date: Sep 2001
Posts: 7
Thanks for that, in the end I used the tid as the unique_id. I tried this originally but as part of a create table1 <table> as
select tid,fileds... from table2.

Tid wouldn't work with the create table statement but if I used the tid as part of an 'insert into ... select tid,fields.. from' then it seemed OK.

Thanks,

Mark
Reply With Quote
  #5 (permalink)  
Old 11-20-02, 11:32
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
It's been a while since I used Ingres but you can generate a sequential key with increments of 1 if you implement something along the lines of:

update yourtable
set unique_id = (
select count(*)
from yourtable a
where yourtable.tid >= a.tid)

Last edited by Damian Ibbotson; 11-26-02 at 08:29.
Reply With Quote
Reply

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