2

I want to add an auto_increment column in an oracle database using liquibase script.

I have tried using the auto_increment attribute in liquibase :

<column name="SUPPLEMENT_ID" type="INTEGER" autoIncrement="true" >
<constraints primaryKey="true"></constraints> 
</column>

If oracle supports auto_increment, how can I achieve it using liquibase scripts?

Théo Winterhalter
  • 4,908
  • 2
  • 18
  • 34
Praveen Kumar
  • 93
  • 1
  • 8
  • 1
    what is your oracle version? autoincriment is only available from version 12 – hotfix Jul 22 '19 at 18:48
  • And what is your Liquibase version? Are you aware that there is no `auto_increment` option in Oracle? If at all it would be `supplement_id integer generated always as identity` –  Jul 22 '19 at 20:22
  • I'm currently using oracle 12. Does it support? – Praveen Kumar Jul 23 '19 at 05:12
  • 1
    Oracle 12c supports IDENTITY columns using the syntax Horse describes. According to [Liquibase Jira site,](https://liquibase.jira.com/browse/CORE-1731) the latest versions should support auto-increment for Oracle 12c. [Find out more](https://github.com/liquibase/liquibase/pull/416) – APC Jul 23 '19 at 07:24

2 Answers2

1

IDENTITY columns are introduced in oracle 12c which allows users to create auto increment columns

But if you are using older versions you have to model the column with sequence and triggers as there is no such option as auto_increment or identity.

Please see this answer on how to do it in both cases https://stackoverflow.com/a/11296469/8330426

harv3
  • 263
  • 1
  • 6
  • 19
1

According to @APC's comment under the question, Liquibase supports Oracle auto increment since version 3.4.0. See https://liquibase.jira.com/browse/CORE-1731.

Vadzim
  • 24,954
  • 11
  • 143
  • 151