ActionRecord: Need for "identity"/"serial" columns?


#1

I have a quick question about ActiveRecord and primary key value
generation.

Does it hurt to define my primary keys as “IDENTITY” (SQL server) or
some equivalent database - managed id generation scheme (a la sequences
in Oracle, etc.) since ActiveRecord is going to manage my id generation
anyway.

I’m thinking that for SQL server, even if you define your ids as
“IDENTITY” it won’t matter because if you specify a value for an
IDENTITY column on an insert, that value will be used instead of the
auto-generated value.

Anyone have any strong feelings either way?

Thanks,
Wes


#2

Wes G. wrote:

I have a quick question about ActiveRecord and primary key value
generation.

Does it hurt to define my primary keys as “IDENTITY” (SQL server) or
some equivalent database - managed id generation scheme (a la sequences
in Oracle, etc.) since ActiveRecord is going to manage my id generation
anyway.

You have to. ActiveRecord doesn’t manage the ID generation - it relies
on the underlying database to do it. Take a look at the defaults
supplied by a simple migrated table structure, and you’ll see what it
expects.