String as Primary Key

Guest Author
Sometimes, we want to set a primary key of a database table to be a string instead of integer. This is perfectly OK though not best.
However, seems this is not possible when creating tables by using ruby on rails. This post helps a lot.
The following is the sample code:
create_table :employees, {:id => false} do |t|
t.string :emp_id
t.string :first_name
t.string :last_name
execute "ALTER TABLE employees ADD PRIMARY KEY (emp_id);"

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.