Professional Web Applications Themes

auto-increment - MySQL

Hi. I'm trying to understand how this works. insert into table_a (opt_id, opt_val_id) values (1,2) The table def is : product_id int notnull opt_id int notnull opt_val_id int notnull When I execute this the product_id auto-increments. There is no trigger or stored proc that I can see. How does the auto-inc occur? thanks...

  1. #1

    Default auto-increment

    Hi.

    I'm trying to understand how this works.

    insert into table_a (opt_id, opt_val_id)
    values (1,2)

    The table def is :

    product_id int notnull
    opt_id int notnull
    opt_val_id int notnull

    When I execute this the product_id auto-increments. There is no
    trigger or stored proc that I can see. How does the auto-inc occur?

    thanks
    tony Guest

  2. #2

    Default Re: auto-increment

    tony wrote: 


    Try

    show create table table_a;

    I bet you'll see something like

    CREATE TABLE `table_a` (
    `product_id` int(11) NOT NULL auto_increment,
    `opt_id` int(11) NOT NULL default '',
    `opt_val_id` int(11) NOT NULL default '',
    PRIMARY KEY (`product_id`)
    ) ENGINE=MyISAM DEFAULT CHT=latin1

    So, because of the "auto_increment" in the `product_id` definition, when
    you insert a row without a specific product_id, the database itself will
    pick a value for it.

    --
    File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot
    Pedro Guest

  3. #3

    Default Re: auto-increment

    tony wrote: 

    The column is defined as an auto_increment attribute.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

Similar Threads

  1. Auto increment VALUE attribute extension
    By arzo2000 in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 1
    Last Post: November 11th, 05:55 PM
  2. Auto Increment increase by 100 at a time?
    By Gary@garywhittle.co.uk in forum MySQL
    Replies: 2
    Last Post: November 23rd, 04:50 PM
  3. How to Handle Primary Key Auto Increment?
    By tbemcf14 in forum Coldfusion - Advanced Techniques
    Replies: 2
    Last Post: March 22nd, 09:47 PM
  4. id after auto increment from a form
    By Faith in forum ASP
    Replies: 7
    Last Post: August 6th, 05:18 PM
  5. Auto Increment a number field
    By jaycee in forum Microsoft Access
    Replies: 0
    Last Post: July 30th, 11:22 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139