Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Oracle style sequences (or Identity cols not tied to a table)

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-06-29 : 09:42:12
Byron writes "Brief question: Is there a way to create a sequence / identity that is not tied to a specific table?

Longer explanation: I have a column that is part of the primary key and need to know the next highest available value. I could do a select to find the max value qualifying on the other part of the primary key but I thought an Oracle style sequence would be better. Then I could just write an insert that includes the proper sequence. It would also be easier for loading configuration data (that I keep in text files). Identity columns don't work because they increase for every row that is added to a table.

Explanation using code:
My table has two key columns and other data columns

TypeKey int -- there are a limited number of types; I'd have a sequence for each type
SeqKey int
Data varchar(100)

If I had three types I'd create sequence A, B and C and then

insert into table (TypeKey, SeqKey, Data) values ('A',A.nextval,'Data for A');
or
insert into table (TypeKey, SeqKey, Data) values ('B',B.nextval,'Data for B');"
   

- Advertisement -