Jump to content

auto increment field type


jpjsmith

Recommended Posts

:oops:

I know this is a very simple question but I could not find (or just didn\'t look long enough) the answer. when creating a table, what is the column type for a field that is automaticaly incremented when not explcitly named in an insert statement? I plan to use this field as a primary key. Thanks for your help!! Yes, I am new to mysql!

Link to comment
Share on other sites

Thanks for responding. The problem is that with both the int and bigint file types, the values do not automatically increment themselves when new entries are made into the table. The values are null or 0 if declared not null in the create table statement. Is there some code to put into the sql that will make the value if the field increment?

Link to comment
Share on other sites

OK, syntax of create:

 

Here is a table for files:


CREATE TABLE files (

 ID int(15) NOT NULL auto_increment,

 path varchar(255) NOT NULL default \'\',

 filename varchar(255) NOT NULL default \'\',

 contents blob NOT NULL,

 PRIMARY KEY  (ID)

) TYPE=MyISAM;

 

 

ID is auto incrementing...

Link to comment
Share on other sites

Great! thanks for helping. this begs one question though, if i use this auto incrementing feild as a primary key, how would i retreive its value so i can use it as a foreign key in another table? thanks again!

Link to comment
Share on other sites

mysql_insert_id

 

refers to the last inserted ID in the auto_increment field.... It\'s thread specific, meaning that if 15 users are connected at the same time, mysql_insert_id will return the correct value to each user (or rather the script he is running (or she)).

 

Look in the php manual for help on this, it\'s quite easy.

 

P.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.