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

Join 117,521 Programmers for FREE! Ask your question and get quick answers from experts. There are 2,086 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



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



Dream Kudos: 50
My Contributions


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


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


Barbarbar

Group Icon
Joined: 3 Oct, 2006
Posts: 1,205



Thanked 9 times

Dream Kudos: 625
My Contributions


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 online!Profile CardPM

Go to the top of the page

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


D.I.C Regular

Group Icon
Joined: 22 Mar, 2007
Posts: 330



Dream Kudos: 50
My Contributions


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

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


D.I.C Regular

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



Thanked 1 times
My Contributions


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

Fast ReplyReply to this topicStart new topic
Time is now: 10/7/08 03:08PM

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