# Active Record and non-numeric, natural primary keys?

**URL:** <https://www.ruby-forum.com/t/active-record-and-non-numeric-natural-primary-keys/73587>\
**Category:** Rails\
**Created:** [October 25, 2006, 3:09pm UTC](https://www.ruby-forum.com/t/active-record-and-non-numeric-natural-primary-keys/73587 "2006-10-25T15:09:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![philpraxis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@philpraxis](https://www.ruby-forum.com/u/philpraxis)\
**Post date:** [October 25, 2006, 3:09pm UTC](https://www.ruby-forum.com/t/active-record-and-non-numeric-natural-primary-keys/73587/1 "2006-10-25T15:09:26Z")

</div>

Hi,

Are we supposed to use numeric, auto-incremented surrogate keys with  
Active Record, or are natural (intelligent), non-numeric primary keys  
perfectly acceptable (advised)?

There is an eternal debate on this subject  
([Intelligent Versus Surrogate Keys](http://www.bcarter.com/intsurr1.htm)), but I was wondering if Active  
Record was designed with the idea of “surrogate keys” in every table.  
That’s what we see mostly in every AR tutorial…

Thanks,

---

<div class="post-metadata">

**Author:** ![philpraxis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@philpraxis](https://www.ruby-forum.com/u/philpraxis)\
**Post date:** [October 25, 2006, 3:34pm UTC](https://www.ruby-forum.com/t/active-record-and-non-numeric-natural-primary-keys/73587/2 "2006-10-25T15:34:33Z")

</div>

The Rails convention is to use an auto-incrementing primary key named id  
on your tables. Rake migrations will create this field automatically.  
You can by all means instruct AR to use your key field instead of the id  
field, but then you are doing extra work.

Your linked article discusses the topic quite well and hits all the  
salient points. If you accept that both methods have pluses and minuses  
of their own accord and are generally no more or less ‘better’ overall  
than each other, then the determining factor in a RoR environment is the  
additional ease of coding and productivity gains to be had by following  
the convention (which in this case is based on a surrogate keys  
framework).

The beauty of Rails … well, one of the beauties of Rails … is that  
you can let Rails handle the mundane grunt-work and you can concentrate  
on design and features. Why be bothered with that stuff?

c.

Philippe L. wrote:

> Hi,
> 
> Are we supposed to use numeric, auto-incremented surrogate keys with  
> Active Record, or are natural (intelligent), non-numeric primary keys  
> perfectly acceptable (advised)?
> 
> There is an eternal debate on this subject  
> ([Intelligent Versus Surrogate Keys](http://www.bcarter.com/intsurr1.htm)), but I was wondering if Active  
> Record was designed with the idea of “surrogate keys” in every table.  
> That’s what we see mostly in every AR tutorial…
> 
> Thanks,
