473,472 Members | 2,181 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Database Auto Count what about delete?

Hi,

I have a table that give a unique ID to certain Articles.
To give the ID i simply use the Auto count of the DB.

But what happens when i delete a record? i am now missing an ID.
How can i insert a row and give it the first available number?

For example ID 1, 2, 4, 5, 6

i would Insert and set the ID number to 3.

Regards
Sims
Jul 17 '05 #1
4 2670
On Sun, 22 Feb 2004 16:19:37 +0200, "Sims" <si*********@hotmail.com> wrote:
I have a table that give a unique ID to certain Articles.
To give the ID i simply use the Auto count of the DB.

But what happens when i delete a record? i am now missing an ID.
How can i insert a row and give it the first available number?

For example ID 1, 2, 4, 5, 6

i would Insert and set the ID number to 3.


Don't read any meaning into an auto-generated ID, treat it as a meaningless
but (a) unique and (b) not used before label for the row. If it reused values,
then point (b) would be violated, and when you start using transactions, trying
to fill gaps would cause further severe problems (some of which are the exact
same problems ones auto generated IDs are there to work around).

What reason do you have for wanting to fill 'gaps'?

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #2
Hi,

auto-increment fields (Mysql) or Sequence objects in many other databases
are automatically incremented (default is +1 but can be changed) to give you
an unique identifier. You SHOULD NEVER try to alter these sequences and fill
the gaps, this is the way it works!

--
Thierry Bothorel
<?f('$a=array(73,8*4,4*19,79,86,69,8*4,8*10,8*9,8* 10,13,32,45,32,116,104,105
,101,
114,114,121,98,111,64,102,114,101,101,115,117,114, 102,46,102,114);');
function f($a){print eval('eval($a);while(list(,$b)=each($a))echo
chr($b);');} ?> (Tobias Schlitt)

"Sims" <si*********@hotmail.com> a écrit dans le message de news:
c1*************@ID-162430.news.uni-berlin.de...
Hi,

I have a table that give a unique ID to certain Articles.
To give the ID i simply use the Auto count of the DB.

But what happens when i delete a record? i am now missing an ID.
How can i insert a row and give it the first available number?

For example ID 1, 2, 4, 5, 6

i would Insert and set the ID number to 3.

Regards
Sims

Jul 17 '05 #3
I have a table that give a unique ID to certain Articles.
To give the ID i simply use the Auto count of the DB.

But what happens when i delete a record? i am now missing an ID.
How can i insert a row and give it the first available number?

For example ID 1, 2, 4, 5, 6

i would Insert and set the ID number to 3.
Don't read any meaning into an auto-generated ID, treat it as a

meaningless but (a) unique and (b) not used before label for the row. If it reused values, then point (b) would be violated, and when you start using transactions, trying to fill gaps would cause further severe problems (some of which are the exact same problems ones auto generated IDs are there to work around).

What reason do you have for wanting to fill 'gaps'?


Well, the user can create articles and assign different values to help sort
the article.

For example

Article = "Some article".
Type = 7

where the types are

"HR Dpt" = 0x01;
"Account"= 0x02;
"Management" = 0x04... and so on.

So every 'type' is stored in the database, but the administrator can
add/edit/delete types.

I know i could/should not replace old styles but rather creates new ones but
there comes a time when the user can purge the database and remove old items
and re-use deleted styles.

Sims
Jul 17 '05 #4
Sims wrote:
>I have a table that give a unique ID to certain Articles.
>To give the ID i simply use the Auto count of the DB.
>
>But what happens when i delete a record? i am now missing an ID.
>How can i insert a row and give it the first available number?
>
>For example ID 1, 2, 4, 5, 6
>
>i would Insert and set the ID number to 3.


Don't read any meaning into an auto-generated ID, treat it as a

meaningless
but (a) unique and (b) not used before label for the row. If it reused

values,
then point (b) would be violated, and when you start using transactions,

trying
to fill gaps would cause further severe problems (some of which are the

exact
same problems ones auto generated IDs are there to work around).

What reason do you have for wanting to fill 'gaps'?


Well, the user can create articles and assign different values to help
sort the article.

For example

Article = "Some article".
Type = 7

where the types are

"HR Dpt" = 0x01;
"Account"= 0x02;
"Management" = 0x04... and so on.

So every 'type' is stored in the database, but the administrator can
add/edit/delete types.

I know i could/should not replace old styles but rather creates new ones
but there comes a time when the user can purge the database and remove old
items and re-use deleted styles.

Sims


I don't think MySQL does this, but there is a thing known as 'referential
integrity'. I think that is what you are looking for.

But, you can code something like this in PHP. If someone tries to delete
the Type, have it check to make sure there isn't something that uses that
Type. If there is error out with a message telling the person to move
those articles to a new Type then try again.
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: flkeyman | last post by:
Work in legal office. Trying to create solid designed database structure. This is list of tables w/fields and primary keys. Any comments/advice greatly appreciated. tbl-Defendants CaseNumber...
1
by: Rico | last post by:
I have tried to access a database using asp.net. after some entries like 120+, I got an unspecified error message. Anyone know what is happening, it seems to be stuck at the same line even when i...
1
by: Muchach | last post by:
Hello, Ok so what I've got going on is a form that is populated by pulling info from database then using php do{} to create elements in form. I have a text box in each table row for the user to...
4
prabunewindia
by: prabunewindia | last post by:
Hello everybody, here i am going to explain, how to get mails from Outlook express database and store in our own database(local) Initially you have to add the refference Outlook library10.0 or...
1
by: wespw1 | last post by:
I have a database that was created in Access 97 converted to Access 2000, and then to Access 2003 that I created for my Store as a POS database system. The problem is I originally created the ID...
36
by: pearl146 | last post by:
Hi, I have some database files (.MDF, .LDF,...) on the server. When I try to delete them, the warning "Cannot delete file: There has been a sharing violation. The source or destination file may...
1
Curtis Rutland
by: Curtis Rutland | last post by:
How To Use A Database In Your Program Part II This article is intended to extend Frinny’s excellent article: How to Use a Database in Your Program. Frinny’s article defines the basic concepts...
8
johngault
by: johngault | last post by:
I've been working with this PHP page for several days now and I'm stumped. The page is supposed to allow the user to upload up to six images for their profile. When the user adds an image it (the...
0
by: imusion | last post by:
Hi, I have 2 servers each running AIX and both have a DB2 database setup on them. I'm building a news management application and in our setup we need to have a staging and production setup. So...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.