Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Auto increment column value while inserting

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
kishpra

New User


Joined: 24 May 2010
Posts: 91
Location: Pune

PostPosted: Wed Feb 05, 2014 3:48 pm    Post subject: Auto increment column value while inserting
Reply with quote

Hi,

i want to insert a row in a table where one col emp_id is set as auto increment e.g.

INSERT INTO
(
col1
emp-id
col2
)
VALUES
(:col1
?
:col2)

Please let me know what ? should be replaced with?


Thanks
Back to top
View user's profile Send private message

harithb

New User


Joined: 08 Jun 2009
Posts: 15
Location: Bangalore

PostPosted: Wed Feb 05, 2014 7:54 pm    Post subject:
Reply with quote

Hi Kishpra,

This would require a sequence to be created first and the NEXTVAL function should be used to assign values to the column.

CREATE SEQUENCE employee_id AS INTEGER

Then use

INSERT INTO
(
col1
emp-id
col2
)
VALUES
(:col1
NEXT VALUE for employee_id
:col2)

Regards,
Haritha.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Feb 06, 2014 2:48 pm    Post subject:
Reply with quote

harithb is right if emp-id is a sequence, not so if it is an identity-column
then you would
Code:
INSERT INTO ... ( col1 ,col2 )
VALUES  (:col1 ,:col2)
and emp-id would be handled for you by DB2.

http://db2portal.blogspot.be/2006/09/sequence-objects-and-identity-columns.html
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm
No new posts Convert rows and column into JSON for... Dinesh Manivannan DB2 2 Sun Sep 03, 2017 6:50 pm
No new posts editting the file by inserting zeros ... pramodrsingh DFSORT/ICETOOL 9 Mon Aug 21, 2017 5:58 pm
No new posts Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am
No new posts Loading data to table gives wrong for... Raghu navaikulam DB2 19 Thu Jul 13, 2017 2:11 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us