简体   繁体   中英

Update table with GENERATED BY DEFAULT AS IDENTITY column

I have a database using Derby and am trying to execute an update statement on a table that has a column with "GENERATED BY DEFAULT AS IDENTITY". I am not trying to update this column, but all of the others.

I can't seem to find the correct syntax to update the rest of the columns without getting errors such as "Attempt to modify an identity column".

Trying to update the table I have been using the UPDATE command,

UPDATE TableName SET Name = '...', ..., WHERE Name = '...'

The first value within the table is an ID field that has the GENERATED BY DEFAULT AS IDENTITY design and I don't want to update this value, I just want to update all of the other fields within the UPDATE command. I don't know how to skip updating this value or simply update the ID field with itself.

Thanks in advance.

So, here's what I did; it worked fine. Can you identify what you are doing differently than this?

ij> create table t1 (a int generated by default as identity, b int);
0 rows inserted/updated/deleted
ij> insert into t1 (b) values (1);
1 row inserted/updated/deleted
ij> update t1 set b=2 where b = 1;
1 row inserted/updated/deleted
ij> select * from t1;
A          |B          
-----------------------
1          |2          
1 row selected

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM