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 > DB2 > IDENTITY funtionality

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-19-04, 10:58
andrewhallam andrewhallam is offline
Registered User
 
Join Date: Dec 2003
Location: Nottingham, England
Posts: 52
IDENTITY funtionality

Does DB2 have an equivalent to MS SQL SERVER's IDENTITY data type ?

For example in SEQUEL you can do this :

create table x
(
a int IDENTITY (1,1) NOT NULL,
b nvarchar(10)
)

This means that when inserting into table 'x' you do not specify a value for x.a - it is automatically generated by sequel - you can then retreive this value using 'SELECT @@IDENTITY'

thanks for any help on this.

Andy.
Reply With Quote
  #2 (permalink)  
Old 01-19-04, 11:52
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Re: IDENTITY funtionality

It is called by the same name ... It can be defined as GENERATED BY DEFAULT or GENERATED ALWAYS ...

There is another object called Sequences in DB2 which is helpful in generating unique values ...

This article should explain
http://www-106.ibm.com/developerwork...2fielding.html
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 01-19-04, 12:12
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Believe it or not, DB2 has another feature like MS SQL Server--manuals! You can down load the manuals in PDF format from the IBM site. Links are available in Useful DB2 Stuff thread.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #4 (permalink)  
Old 03-05-04, 10:00
andrewhallam andrewhallam is offline
Registered User
 
Join Date: Dec 2003
Location: Nottingham, England
Posts: 52
Re: IDENTITY funtionality

Sorry for not replying sooner - other projects...

Yeah, I know about DB2's IDENTITY data type.
The thing I need to know about though is retreival.

SQL SERVER populates its @@IDENTITY value with the last identity value generated in any table in the current session. This guarantees that you will only get back the IDENTITY value that "you" created and nobody else's.

My question seems to be a very popular one as it appears on various forums but as yet I have not found any answers.

Thanks for any help on this.

Andy.
Reply With Quote
  #5 (permalink)  
Old 03-26-04, 09:37
hurmavi hurmavi is offline
Registered User
 
Join Date: Jan 2004
Location: Europe, Finland, Helsinki
Posts: 60
Re: IDENTITY funtionality

Hi

DB2 has funtion IDENTITY_VAL_LOCAL() and it's doing exatly the same thing.

(However, as I'm a OS/390 man - I cannot be 100% sure if it will on UDB)

"...SQL SERVER populates its @@IDENTITY value with the last identity value generated in any table in the current session. This guarantees that you will only get back the IDENTITY value that "you" created and nobody else's..."

Cheers, Bill
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