Engine by engine
Same intent, incompatible syntax: SERIAL, IDENTITY, AUTO_INCREMENT, rowid aliasing and GENERATED AS IDENTITY, plus per-engine gaps and quirks.
| エンジン | 型 | ストレージ | メモ |
|---|---|---|---|
| SQL Server |
INT IDENTITY(1,1)
|
4 bytes | IDENTITY is a column property, not a type; BIGINT IDENTITY for larger ranges. |
| PostgreSQL |
SERIAL / BIGSERIAL
|
4 / 8 bytes | Shorthand for an INTEGER (or BIGINT) with a sequence-backed default; GENERATED AS IDENTITY is the modern spelling. |
| MySQL |
INT AUTO_INCREMENT
|
4 bytes | A column attribute that must be indexed; at most one AUTO_INCREMENT column per table. |
| SQLite |
INTEGER PRIMARY KEY AUTOINCREMENT
|
up to 8 bytes | Any INTEGER PRIMARY KEY auto-assigns rowids; AUTOINCREMENT additionally forbids reusing deleted ids. |
| Oracle |
INT GENERATED ALWAYS AS IDENTITY
|
1-21 bytes | Identity columns since 12c; older code pairs sequences with triggers or a default of seq.NEXTVAL. |
Gotchas
Where the engines disagree. These tend to surface as bugs during a migration or a port.
- SERIAL is not standard SQL: the same intent appears as IDENTITY (SQL Server, Oracle), AUTO_INCREMENT (MySQL) and implicit rowids (SQLite), so DDL never ports verbatim.
- SQL Server, PostgreSQL, MySQL and Oracle burn values on rolled-back or failed inserts. SQLite is the exception: a rolled-back insert does not consume a rowid. Never build logic on gap-free keys.
- MySQL allows at most one AUTO_INCREMENT column per table, and it must be indexed (error 1075 otherwise).
- SQLite's AUTOINCREMENT keyword is usually unnecessary: a plain INTEGER PRIMARY KEY already auto-assigns, and AUTOINCREMENT adds a sqlite_sequence table and overhead.
- Inserting explicit IDs desynchronizes counters differently: PostgreSQL's serial accepts them and leaves the sequence behind (the next default collides), MySQL moves its counter past them, SQL Server needs SET IDENTITY_INSERT first.
Common questions
Is SERIAL a data type?
In PostgreSQL it is shorthand for INTEGER plus a sequence-owned default; BIGSERIAL does the same for BIGINT. GENERATED ALWAYS AS IDENTITY is the standards-based replacement.
Do auto-increment counters have gaps?
Yes. In SQL Server, PostgreSQL, MySQL and Oracle, rolled-back or failed inserts consume values permanently. SQLite hands out max(rowid)+1, so rollbacks leave no gap, but deletes do. Treat the counter as a unique source, not a row count.
How do I auto-increment in SQLite?
Declare the column INTEGER PRIMARY KEY. SQLite aliases it to the rowid and assigns increasing values automatically; AUTOINCREMENT only adds reuse protection.
Map a type to the other four engines
The free type converter maps a type from one engine to its closest equivalent in the others and says where storage, precision or behaviour differ. The desktop app does the same mapping while you edit.