# Every table must have an id

**URL:** <https://www.ruby-forum.com/t/every-table-must-have-an-id/51182>\
**Category:** Rails\
**Created:** [December 27, 2005, 7:47pm UTC](https://www.ruby-forum.com/t/every-table-must-have-an-id/51182 "2005-12-27T19:47:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![farooq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/919ad9/32.png) [@farooq](https://www.ruby-forum.com/u/farooq)\
**Post date:** [December 27, 2005, 7:47pm UTC](https://www.ruby-forum.com/t/every-table-must-have-an-id/51182/1 "2005-12-27T19:47:25Z")

</div>

Hello,  
Not sure if this is implied in the documentation or something given:  
does the RoR framework require “every table must have an id” ? If this  
is the case, then what happened to the concept of normalization ?  
Futher, if the tables have already been build for an existing  
appication ( without ID column in everytable ) , will the script /  
generate work ?

Thanks

---

<div class="post-metadata">

**Author:** ![farooq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/919ad9/32.png) [@farooq](https://www.ruby-forum.com/u/farooq)\
**Post date:** [December 27, 2005, 10:43pm UTC](https://www.ruby-forum.com/t/every-table-must-have-an-id/51182/2 "2005-12-27T22:43:11Z")

</div>

Yes. Every table must have an ID, but I believe you could call it  
something else (mainly to assist with legacy tables).

Normalization has nothing to do with not having an ID column.  
Normalization is a process the exists independent of the idea of a  
column called ID. You could do it with a meaningful column like  
social-insurance number. However, meaningless ID columns are a wiser  
choice.

if you don’t have an id column then updates/edits won’t work.

bruce

---

<div class="post-metadata">

**Author:** ![farooq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/919ad9/32.png) [@farooq](https://www.ruby-forum.com/u/farooq)\
**Post date:** [December 27, 2005, 8:24pm UTC](https://www.ruby-forum.com/t/every-table-must-have-an-id/51182/3 "2005-12-27T20:24:38Z")

</div>

Hi !

2005/12/27, Farooq [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Not sure if this is implied in the documentation or something given:  
> does the RoR framework require “every table must have an id” ? If this  
> is the case, then what happened to the concept of normalization ?  
> Futher, if the tables have already been build for an existing  
> appication ( without ID column in everytable ) , will the script /  
> generate work ?

Yes, all tables need an ID or equivalent column. It need not be  
called ID (see #set\_primary\_key  
[Peak Obsession](http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000741)).

Normalization only ensures that the customer’s address is not repeated  
in more than one table. That’s why we use IDs to get at the  
customer’s record.

Never tried it myself, but script/generate scaffold should work with  
your existing tables. You will need to change the generated models to  
set your primary key, though.

Hope that helps !

---

<div class="post-metadata">

**Author:** ![farooq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/919ad9/32.png) [@farooq](https://www.ruby-forum.com/u/farooq)\
**Post date:** [December 28, 2005, 3:04pm UTC](https://www.ruby-forum.com/t/every-table-must-have-an-id/51182/4 "2005-12-28T15:04:30Z")

</div>

On Tue, Dec 27, 2005 at 02:21:49PM -0500, Francois B. wrote:  
} Hi !  
}  
} 2005/12/27, Farooq [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):  
} \> Not sure if this is implied in the documentation or something  
given:  
} \> does the RoR framework require “every table must have an id” ? If  
this  
} \> is the case, then what happened to the concept of normalization ?  
} \> Futher, if the tables have already been build for an existing  
} \> appication ( without ID column in everytable ) , will the script /  
} \> generate work ?  
}  
} Yes, all tables need an ID or equivalent column. It need not be  
} called ID (see #set\_primary\_key  
} [Peak Obsession](http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000741)).  
}  
} Normalization only ensures that the customer’s address is not repeated  
} in more than one table. That’s why we use IDs to get at the  
} customer’s record.  
}  
} Never tried it myself, but script/generate scaffold should work with  
} your existing tables. You will need to change the generated models to  
} set your primary key, though.

Is there support for multi-column keys? I have a situation in which the  
most reasonable schema has a table with a two-column key: the pairing of  
a  
foreign key and an ordering value. It is a simple has\_many situation,  
and  
there is no reason to interact with records of the model outside the  
dependent has\_many collection.

} Hope that helps !  
} –  
} Fran??ois Beausoleil  
–Greg

---

<div class="post-metadata">

**Author:** ![farooq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/919ad9/32.png) [@farooq](https://www.ruby-forum.com/u/farooq)\
**Post date:** [December 28, 2005, 3:10pm UTC](https://www.ruby-forum.com/t/every-table-must-have-an-id/51182/5 "2005-12-28T15:10:32Z")

</div>

> Is there support for multi-column keys? I have a situation in which the  
> most reasonable schema has a table with a two-column key: the pairing of a  
> foreign key and an ordering value. It is a simple has\_many situation, and  
> there is no reason to interact with records of the model outside the  
> dependent has\_many collection.

Not really, but you can get around it. I’d suggest using a normal  
primary key anyway, it’ll be a _LONG_ time before you run out of IDs.

–  
rick  
[http://techno-weenie.net](http://techno-weenie.net)
