Welcome to Dream.In.Code
Getting Help is Easy!

Join 86,399 Programmers. There are 1,454 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

autoincrement option when creating tables

 
Reply to this topicStart new topic

autoincrement option when creating tables

spullen
post 8 Jun, 2007 - 03:25 PM
Post #1


D.I.C Regular

Group Icon
Joined: 22 Mar, 2007
Posts: 330



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

Thanks
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


girasquid
post 8 Jun, 2007 - 03:34 PM
Post #2


Barbarbar

Group Icon
Joined: 3 Oct, 2006
Posts: 953

Yes. You can use the auto_increment keyword when naming your columns.
CODE

CREATE TABLE demo (
id int auto_increment,
PRIMARY KEY(id)
);
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

spullen
post 9 Jun, 2007 - 08:27 AM
Post #3


D.I.C Regular

Group Icon
Joined: 22 Mar, 2007
Posts: 330

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

CODE

def self.up
    create_table :persons do |t|
      t.column :id, :integer, :auto_increment # the auto_increment part is this right?
    end
end
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

theRemix
post 10 Jun, 2007 - 03:47 AM
Post #4


D.I.C Regular

***
Joined: 19 Oct, 2005
Posts: 359

QUOTE(spullen @ 9 Jun, 2007 - 08:27 AM) *

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

CODE

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
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 06:13AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month