I'm working with Spring and Hibernate to develop web applications in Java. Let's assume that I have a table. When I delete some records from this table, sometimes I need to reset the value of the primary key field.
Let's say that I have 10 records in a table and I delete the last 5 records. Now, when I insert new records, the value of the primary key field should be started at
6 but it would start at
If I need to start the primary key value at
maximum +1) in MySql, I just need to execute the following SQL statement.
alter table table_name auto_increment=1;
This will automatically reset the value of
maximum + 1 value of that field (May conceptually be incorrect but it works).
In Oracle (10g), I'm using
sequence with the primary key. Is there a way in Oracle to reset the value of the
maximum + 1 value when some records are deleted from the database?