Modifing db

If I am going to build a sql database for use in rails (rather than
building it in rails), is there anything I need to know beyond using an
id column in every table? Does the id need to be the “primary key”?

Mk 27 wrote:

If I am going to build a sql database for use in rails (rather than
building it in rails), is there anything I need to know beyond using an
id column in every table? Does the id need to be the “primary key”?

By convention, rails would look for an id as a primary key for all
tables. Also, if you use rails migrations to generate the tables, you
can say -
create_table(:table_name, :id => false) if you don’t want id.
This might be required in case your table is from a legacy system.

Thanks

Yes, the id needs to be the primary key.

Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)

The id should be an auto-incrementing primary key.
Also, column names should be lower cased using an underscore to
separate words, i.e. first_name
You should also consider adding “created_at” and “updated_at” datetime
fields to handle timestamps.

Table names should be pluralized.

E. Litwin wrote:

The id should be an auto-incrementing primary key.
Also, column names should be lower cased using an underscore to
separate words, i.e. first_name
You should also consider adding “created_at” and “updated_at” datetime
fields to handle timestamps.

Table names should be pluralized.

Thanks. I just realized I confused this post with one I forgot writing
yesterday. This looks like the info I need.

Does the id need to be the “primary key”?

You can set your own primary key like

def self.up
create_table :table_name, :primary_key => :primary_key_field_name, do
|t|
t.integer :primary_key_field_name
---------
end

Sijo

Mk 27 wrote:

If I am going to build a sql database for use in rails (rather than
building it in rails),
[…]

Why would you do that? I understand the use case of a preexisting
“legacy” DB, but if you’re building a DB from scratch for use with a
Rails app, then it’s just more efficient to use the DB tools that Rails
provides.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]