Results 1 to 5 of 5

Thread: inset in mysql with auto_increment,

  1. #1
    Join Date
    Jul 2003
    Posts
    421

    inset in mysql with auto_increment,

    hi all , I have a simple table in mysql
    Code:
    drop  table  setrules  if exists setrules;
    create table setrules(
       ID int(10) unsigned NOT NULL auto_increment,
      STime  time NOT NULL default '00:00:00',
      ETime    time  Not NULL    default    '00:00:00' ,
      DATE date NOT NULL default '0000-00-00',
      Primary key(ID));
    insert into setrules
    values(2 , '12:00:00', '13:00:00', '2006-11-14')
    why I need to insert 2 in here , when the id is set to auto_ increment, why I still need to insert the ID number ?
    Thank you
    ________
    NEW JERSEY MEDICAL MARIJUANA DISPENSARY
    Last edited by sql; 03-06-2011 at 02:01 AM.

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    Does insert statement work if you take out id number?

  3. #3
    Join Date
    Sep 2005
    Posts
    168
    You dont have to set manually the value of an auto increment field UNLESS you want to.
    MySql allows the manual value adjustment on auto increment fields.

    --HTH--

  4. #4
    Join Date
    Jul 2003
    Posts
    421
    the problem is I have to insert the Id number by hand , other wise I will got something like Colum conut doesn't match value count at row 1,
    that is the problem for me, since we will use in on web how can the user know what is the id number it suppose be, do I create my table wrong ,? what stuid mistake I made?
    Thank you
    ________
    TRICHOMES PICTURES
    Last edited by sql; 03-06-2011 at 02:01 AM.

  5. #5
    Join Date
    Sep 2005
    Posts
    168
    Note: It is better practise to write/mention the columns of the table:

    insert into setrules(STime, ETime, Date)
    values('12:00:00', '13:00:00', '2006-11-14')

    OR

    insert into setrules(ID, STime, ETime, Date)
    values(NULL, '12:00:00', '13:00:00', '2006-11-14')

    OR

    insert into setrules
    values(NULL, '12:00:00', '13:00:00', '2006-11-14')

    by supplying NULL to an autoincrement field, MySql adds the next available value to this field

    --HTH--

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •