Reply to this topicStart new topic
> Ms Access Database Pros, a little help to those in the know
DeepRoots
post Feb 16 2008, 06:28 PM
Post #1


Get to da Chopper!
Group Icon

Group: GMC Senior
Posts: 2.700
Joined: 18-March 07
From: South Wales, UK
Member No.: 1.374



Hey guys this one is for any database know-it-alls

im making a car rental database for my IT project, and in the "Loans" table i have set "Loan number" as the primary key and an autonumber.

What i want is a random number to appear in the table for each loan entry- i have set a random number to appear but i'm interested if i can format this so that only positive values are generated.. and also if i can set a data range for the number .. say 1 -1000.

Thanks for any help- i know there's alot of IT guys out there so im counting on ya wink.gif
Go to the top of the page
 
+Quote Post
Pavel
post Feb 16 2008, 06:53 PM
Post #2


Instructor
*

Group: Passive
Posts: 3.764
Joined: 8-January 07
From: Rijeka, Croatia
Member No.: 1.055



Isn't it easier to make it an auto-increment value starting from 1? With random generating you may run in a problem of hitting the same number and you'll fail to update the table (this is extremely rare in a range of 1-1000 but it may happen, while with auto-increment it will never happen).

I hope someone will give you the answer you're looking for, but in MySQL database i always do it with auto-increment value.


--------------------
"It isn't how many years you have been playing, it's how many hours." -- Prashant Aswani

"PRACTICE, PRACTICE, PRACTICE!" -- Michael Angelo Batio

Check out my video lessons and instructor board!

Go to the top of the page
 
+Quote Post
DeepRoots
post Feb 16 2008, 06:57 PM
Post #3


Get to da Chopper!
Group Icon

Group: GMC Senior
Posts: 2.700
Joined: 18-March 07
From: South Wales, UK
Member No.: 1.374



QUOTE (Pavel @ Feb 16 2008, 05:53 PM) *
Isn't it easier to make it an auto-increment value starting from 1? With random generating you may run in a problem of hitting the same number and you'll fail to update the table (this is extremely rare in a range of 1-1000 but it may happen, while with auto-increment it will never happen).

I hope someone will give you the answer you're looking for, but in MySQL database i always do it with auto-increment value.


cheers Pavel i'll give it a shot your way if i dont find the answer smile.gif
Go to the top of the page
 
+Quote Post
Ivan Milenkovic
post Feb 17 2008, 04:34 PM
Post #4


Instructor
Group Icon

Group: GMC Instructor
Posts: 25.396
Joined: 20-November 07
From: Belgrade, Serbia
Member No.: 3.341



You never set range for primary key man. It doesn't makes sense because when you insert more than 1000 rows in your table (and that will happen sooner than you think believe me), the error will occur. Pavel said it right. You have to set the autonumber value for all your primary keys. Access does this by default anyway so there is no reason complicating. There is no point inserting random number as you primary key anyway.


--------------------
- Ivan's Video Chat Lesson Notes HERE
- Check out my GMC Profile and Lessons
- (Please subscribe to my) YouTube Official Channel
- Let's be connected through ! Facebook! :)
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


RSS Lo-Fi Version Time is now: 27th July 2017 - 01:51 PM