Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > General > Database Concepts & Design > auto_increment primary key

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-05-08, 17:51
lmei007 lmei007 is offline
Registered User
 
Join Date: Jun 2008
Posts: 18
auto_increment primary key

we can use integer as a table unique primary key and we can let the database to assign an unique number to it via the auto_increment property. Saying we can have a custId integer field as the only primary key and let the MySQL database automatically increase one each time a new customer is inserted. But I am not clear about this concept.

1. does that auto_increment property is defined in SQL or in DBMS or in individual database implementation?

2. in the insert SQL statement we should ignore that field (custId) because database will automatically assign a value to it?

3. if my data is huge, is there any chance the integer value gets overflow if the database keep increase it?

4. When we should use the auto_increment feature and when we should not use it?

5. After compare the output sql file, I noticed that some modeler software support such feature but others did not. what does this mean?
Reply With Quote
  #2 (permalink)  
Old 06-05-08, 17:58
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,538
1. the auto_increment feature is not part of standard SQL

however, most database systems find it very useful, and have implemented something for it

MySQL: auto_increment
SQL Server: identity
Oracle: sequence
etc.

2. yes

3. yes, but if you use INTEGER then you will typically need to redesign your database long before you hit the limit

and if you use BIGINT, i guarantee you will never have too many rows

4. when you need a surrogate key -- i'm sorry if this is not a big explanation, so you should do some research on that term

5. it might mean you need to choose your modelling software with care
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #3 (permalink)  
Old 06-05-08, 18:01
blindman blindman is online now
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 9,274
1) Implementation of Identity columns varies between database platforms.

2) Yes.

3) Perhaps sometime shortly before the Earth is engulfed by the Sun.

4) Sometimes you should use it some of the time. Other times you should use it either none of the time, or all of the time. Depends on what time it is.

5) It means some software is better than others.
__________________
If it's not practically useful, then it's practically useless.

blindman
http://sqlblindman.googlepages.com/main
Reply With Quote
  #4 (permalink)  
Old 06-05-08, 18:04
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,538
i am amazed at how closely our answers agree, blindman

thank $deity you did not answer "4. all the time" (but just hang on, pat will be along in a moment, he'll do it)
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #5 (permalink)  
Old 06-06-08, 01:11
blindman blindman is online now
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 9,274
I confess. I copied your answers while looking over your shoulder.
__________________
If it's not practically useful, then it's practically useless.

blindman
http://sqlblindman.googlepages.com/main
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On