Forum: Ruby on Rails ActionRecord: Need for "identity"/"serial" columns?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-14 20:42
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
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-03-14 21:40
(Received via mailing list)
Wes Gamble 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.
This topic is locked and can not be replied to.