Unix Technical Forum

auto-increment

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 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 08:18 AM
tony
 
Posts: n/a
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 08:18 AM
Jerry Stuckle
 
Posts: n/a
Default Re: auto-increment

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
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 08:18 AM
Pedro Graca
 
Posts: n/a
Default Re: auto-increment

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:23 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com