473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Identity column

I have a table defined as

CREATE TABLE MYTABLE (
BENEF_ID INT NOT NULL GENERATED ALWAYS AS IDENTITY(START WITH 1
INCREMENT BY 1),
LAST_NAME CHAR(20));

insert into mytable
(select sysibm.identity_val_local(),bnf_last_nm from
claimsa.tbeneficiary)

This gives the following error.
insert into mytable (select sysibm.identity_val_local(),bnf_last_nm
from claimsa.tbeneficiary)

DB21034E The command was processed as an SQL statement because it was
not a

valid Command Line Processor command. During SQL processing it
returned:

SQL0798N A value cannot be specified for column "BENEF_ID" which is
defined

as GENERATED ALWAYS. SQLSTATE=428C9
Nov 12 '05 #1
4 17348
dharmadam wrote:
CREATE TABLE MYTABLE (
BENEF_ID INT NOT NULL GENERATED ALWAYS AS IDENTITY(START WITH 1
INCREMENT BY 1),
LAST_NAME CHAR(20));

insert into mytable(LAST_NAME)
(select bnf_last_nm from claimsa.tbeneficiary)

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
The message is self-explanatory. You cannot specify a value for an
identity col. which generated always.
Db2 will start with value (1) in your case and increment as you go.

Your statement should then be:
insert into mytable (select bnf_last_nm from claimsa.tbeneficiary where
????????)
the function identity_val_local applies to retrieve the value of the
just inserted row in a table that has an identity col. defiend.
HTH, Pierre.

dharmadam wrote:
I have a table defined as

CREATE TABLE MYTABLE (
BENEF_ID INT NOT NULL GENERATED ALWAYS AS IDENTITY(START WITH 1
INCREMENT BY 1),
LAST_NAME CHAR(20));

insert into mytable
(select sysibm.identity_val_local(),bnf_last_nm from
claimsa.tbeneficiary)

This gives the following error.
insert into mytable (select sysibm.identity_val_local(),bnf_last_nm
from claimsa.tbeneficiary)

DB21034E The command was processed as an SQL statement because it was
not a

valid Command Line Processor command. During SQL processing it
returned:

SQL0798N A value cannot be specified for column "BENEF_ID" which is
defined

as GENERATED ALWAYS. SQLSTATE=428C9


--
Pierre Saint-Jacques - Reply to: sesconsjunk at attglobaljunk dot com
Reconstruct address: Remove the two junk and replace at and dot by
their symbols.
IBM DB2 Cerified Solutions Expert - Administration
SES Consultants Inc.

Nov 12 '05 #3
Serge Rielau <sr*****@ca.eye-be-em.com> wrote in message news:<c8**********@hanover.torolab.ibm.com>...
dharmadam wrote:
CREATE TABLE MYTABLE (
BENEF_ID INT NOT NULL GENERATED ALWAYS AS IDENTITY(START WITH 1
INCREMENT BY 1),
LAST_NAME CHAR(20));

insert into mytable(LAST_NAME)
(select bnf_last_nm from claimsa.tbeneficiary)

Cheers
Serge

Thanks Serge. You have answer for everything.
Nov 12 '05 #4
Tarrot Cards, DB2 edition :-)
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: grzes | last post by:
MS SQL Server 2000. My case is: I have the table T with primary key calling __recid int without identity property. This table includes a lot of records (about 1000000). I need to convert __recid's...
4
by: UDBDBA | last post by:
Hi: we have column with GENERATED ALWAYS AS DEFAULT. So, we can insert into this column manually and also let db2 generate a value for this column. Given a scenario, how can i find the NEXTVAL...
3
by: mal_k100 | last post by:
Hi All, 1. Created table in SQL Server 2K with Primary key as int Identity 2. Link to table in MS Access 2K 3. Using form in MSAccess to update the linked table I want SQL server to...
2
by: WhiteEagl | last post by:
Hello, I would need some help with this identity column problem in SQLServer. I have a database with two tables. The Parent table has an Identity column. Parent (ParentID IDENTITY, Name)...
2
by: .Net Newbie | last post by:
Hello, I am somewhat new to .Net and currently working on an intranet site using C# going against SQL Server 2k. I am accepting personal information on a single webform and trying to insert the...
1
by: smauldin | last post by:
Creating a table with an identity column works fine create table test(a integer, id integer generated always as identity ) When I attempt to add an identity column it fails. create table...
4
by: shorti | last post by:
Can anyone explain in greater (and more comprehensive) detail what the RESTART option does in the ALTER TABLE table ALTER COLUMN statement. This is the description in Info Center: RESTART or...
5
by: Veeru71 | last post by:
Given a table with an identity column (GENERATED BY DEFAULT AS IDENTITY), is there any way to get the last generated value by DB2 for the identity column? I can't use identity_val_local() as...
3
by: Rob | last post by:
Hi all, I have a bit of a complicated question, hope we have an SQL guru out there that can help us solve this killer problem. Due to the size of SQL Database we have (largest in the US), we...
13
by: PinkBishop | last post by:
I am using VS 2005 with a formview control trying to insert a record to my access db. The data is submitted to the main table no problem, but I need to carry the catID to the bridge table...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.