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 > what is the autonumber datatype for DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-10-04, 16:51
jpalazzi jpalazzi is offline
Registered User
 
Join Date: Nov 2004
Posts: 16
Exclamation what is the autonumber datatype for DB2

I am used to using SQL server and access, what is the command for an autonumber is it an identity type? how do you set things like where you want it to begin?

Thanks for the help guys
Reply With Quote
  #2 (permalink)  
Old 11-11-04, 09:51
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally Posted by jpalazzi
I am used to using SQL server and access, what is the command for an autonumber is it an identity type? how do you set things like where you want it to begin?

Thanks for the help guys
Identity:
CREATE TABLE A (
ID INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY ( START WITH +1 , INCREMENT BY +1 , NO CACHE )
);

See the SQL Ref for more detail, but that's the bones of it.
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #3 (permalink)  
Old 11-11-04, 16:04
jpalazzi jpalazzi is offline
Registered User
 
Join Date: Nov 2004
Posts: 16
I got the create table to work.
I tried an insert though and it keeps erroring out.

I did: insert into test values(smith);

i made 2 fields id which was the autonumber and then one that was lname and it was char.

any ideas?
Reply With Quote
  #4 (permalink)  
Old 11-11-04, 16:36
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Your insert should be:

insert into test (lname) values('smith');


Andy
Reply With Quote
  #5 (permalink)  
Old 11-11-04, 17:14
jpalazzi jpalazzi is offline
Registered User
 
Join Date: Nov 2004
Posts: 16
that seemed to work , but i thought you didnt have to put the fields you are inserting into as long as they were in the same order?
Reply With Quote
  #6 (permalink)  
Old 11-12-04, 07:55
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally Posted by jpalazzi
that seemed to work , but i thought you didnt have to put the fields you are inserting into as long as they were in the same order?
If you have 2 columns and you're only supplying a value for 1, you need to supply the column list. The implicit column list only works if you're providing all values.
__________________
--
Jonathan Petruk
DB2 Database Consultant
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