This is a discussion on auto-increment within the MySQL forums, part of the Database Server Software category; --> 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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 wrote: > 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 The column is defined as an auto_increment attribute. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
| ||||
| tony wrote: > 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? 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 CHARSET=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 |
| Thread Tools | |
| Display Modes | |
|
|