3 Replies - 5537 Views - Last Post: 10 June 2007 - 03:47 AM Rate Topic: -----

#1 spullen  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 356
  • Joined: 22-March 07

autoincrement option when creating tables

Post icon  Posted 08 June 2007 - 03:25 PM

Quick question, is there an option when creating columns for a table to have a column autoincrement, for a mySQL database?

Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: autoincrement option when creating tables

#2 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: autoincrement option when creating tables

Posted 08 June 2007 - 03:34 PM

Yes. You can use the auto_increment keyword when naming your columns.
CREATE TABLE demo (
id int auto_increment,
PRIMARY KEY(id)
);


Was This Post Helpful? 0
  • +
  • -

#3 spullen  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 356
  • Joined: 22-March 07

Re: autoincrement option when creating tables

Posted 09 June 2007 - 08:27 AM

Yeah but how would you do that in a migration file.
like:

def self.up
	create_table :persons do |t|
	  t.column :id, :integer, :auto_increment # the auto_increment part is this right?
	end
end


Was This Post Helpful? 0
  • +
  • -

#4 theRemix  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 440
  • Joined: 19-October 05

Re: autoincrement option when creating tables

Posted 10 June 2007 - 03:47 AM

View Postspullen, on 9 Jun, 2007 - 08:27 AM, said:

Yeah but how would you do that in a migration file.
like:

def self.up
	create_table :persons do |t|
	  t.column :id, :integer, :auto_increment # the auto_increment part is this right?
	end
end



you don't need to even specify that column, the migration should create the id column automatically, makes it primary key and auto_increment.

so just don't write that line, and it'll be created for you ok?

hth
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1