> Hi I'm relatively new to MySQL though I familiar to other simple 
> databases.

Ahem... [takes Sumarlidi aside and explains very carefully how the
MySQL developers feel about hearing MySQL being called a "simple 
database" ;-) ]

> I have been reading the manual but not doing well understanding 
> the function
> of auto_increment and Premier Key.
> 
> Lets say I have a table with a few columns. One of them is an ID with
> auto_increment. It has 1000 rows. If I delete row #500 to #599 (total of
> 100), will the MySQL update the ID value for row #600 to #1000, 

No.

> or will it stay as it was?

Yes. The whole point of having such a column is to create and 
maintain a unique identifier for the record for as long as it
lives.

> If it stays as it was, and afterwards when I add a row (or 
> record), will it
> continue from row #1001 or will it use the value from #500 to #599?

#1001 (same argument -- you don't want something you thought
was dead and gone to seemingly reappearing all of a sudden)

> 
> What is the Primary Key used for and how does it work? Do I need it if I
> have a row ID like mentioned above?

In most cases, this is the primary function of the primary key.
The primary key is unique in a couple of respects: 1) it is always
declared as NOT NULL UNIQUE, meaning that you're ensured that
for any record there is always a well-defined, distinct ID as you
must always declare it (or have MySQL do it for you through 
auto_increment) and you can never assign the same value to two
different rows; You may have other UNIQUE indexes; however, there
are some subtle differences between these and a primary key.
errrr... hmmmm... I'm sure there are. Though for the life of me, 
I can't think of any off the top of my head right now. I'll go
get some coffee while someone else explains this to you.


/ Carsten
--
Carsten H. Pedersen
keeper and maintainer of the bitbybit.dk MySQL FAQ
http://www.bitbybit.dk/mysqlfaq


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to