# insert/update change one column

**URL:** <https://forum.servoy.com/t/insert-update-change-one-column/19605>\
**Category:** Classic Servoy\
**Created:** [February 18, 2018, 8:51am UTC](https://forum.servoy.com/t/insert-update-change-one-column/19605 "2018-02-18T08:51:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobm](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@bobm](https://forum.servoy.com/u/bobm)\
**Post date:** [February 18, 2018, 8:51am UTC](https://forum.servoy.com/t/insert-update-change-one-column/19605/1 "2018-02-18T08:51:44Z")

</div>

I’m looking to copy and insert multiple rows from the same table, changing the data in one column on the insert. I’m running into a conflict with the ‘record\_id’ - I’ve also tried this code below without the record\_id - I’m getting either “record\_id already exists” or “not-null constraint”

```auto
insert into table1 (record_id, columnA, columnB, columnC)
select record_id, columnA, columnB, '123456789'
from table1
where record_id between 1710330 and 1710500

```

Thanks in advance for any suggestions.

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [February 18, 2018, 12:49pm UTC](https://forum.servoy.com/t/insert-update-change-one-column/19605/2 "2018-02-18T12:49:57Z")

</div>

Hi Bob,

Your query selects and then inserts the record\_id value, so this will trigger the unique constraint.  
Now if you don’t select/insert the record\_id column and you don’t use database sequences/identities then you get a not-null constraint error.

So the fix is to make the PK value database managed (db identity or db sequence, depending on the db vendor) and then use the following SQL:

```auto
INSERT into table1 (columnA, columnB, columnC)
SELECT columnA, columnB, '123456789'
FROM table1
WHERE record_id BETWEEN 1710330 AND 1710500

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![bobm](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@bobm](https://forum.servoy.com/u/bobm)\
**Post date:** [February 18, 2018, 10:07pm UTC](https://forum.servoy.com/t/insert-update-change-one-column/19605/3 "2018-02-18T22:07:44Z")

</div>

Thanks Robert

I’ll give that a shot
