Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Surrogate Key 1

Status
Not open for further replies.
Jun 1, 2006
58
US

Hi all,

I am trying to declare a surrogate key for a table and I get an error saying invalid datatype.

Here is what I am doing. I have created a sequence to generate numbers lets say SEQ.

I am declaring the key as

ID SEQ.nextval in the CREATE TABLE statement and it is giving me an error. I am new to surrogate keys, I've never used them.

Appreciate your help.

Thanks.
 
You can only use a sequence in a SELECT or part of an INSERT etc.
 
Hi Lewis,

Yes..I realise I will have to create the sequence first and then insert into the table.

However, will I have to insert into the table one row at a time using seq.nextval function? If I wanted to insert multiple rows into the table, then I will have to use a loop i am thinking.

Is there any other way?

appreciate ur help.
 
There are two ways to insert. One is [tt]INSERT INTO table (column, column,...) VALUES (seq.nextval, value...);[/tt]

Or you can use [tt] INSERT INTO table (column, column...) SELECT seq.nextval, column FROM table...[/tt]

The first example would require a loop but the second will insert as many rows as are found in the SELECT.
 
Thanks to both of you..

I did create a trigger to input the sequence value and it works great..

thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top