Database-Specific Troubleshooting
Fixes for problems that come from one database’s behavior or its JDBC driver.
| Database | Pages and sections |
|---|---|
PostgreSQL |
|
MySQL |
|
Oracle |
|
SQL Server |
|
Any database |
MySQL
Oracle
ORA-00001: Unique Constraint Violated
Issue: Sequence values conflict with existing data.
Solution: Reset sequences before generation (Oracle 18c and later). First find the next free value:
SELECT MAX(id)+1 FROM customer;
Then restart the sequence at that value, replacing <next-value> with the result of the query:
ALTER SEQUENCE customer_seq RESTART START WITH <next-value>;
See also Oracle sequences.
SQL Server
Identity Columns
Issue: Cannot insert into IDENTITY columns.
Solution: The platform handles identity columns itself. Don’t give an identity column a transformer that sets its values. To find the identity columns:
-- Check IDENTITY columns
SELECT name, is_identity
FROM sys.columns
WHERE object_id = OBJECT_ID('dbo.customers');