Solved

o.k i have a problem, when i delet something from a table its idea number never comes back

Posted on 2008-06-09
8
241 Views
Last Modified: 2010-04-21
o.k lets say i have a table named place1
and it have

id  -   place
1  -    idms
2  -    sds
3  -   dfdf
4 -    dffsf

and lets say i delet id number 4
and i insert onther field
dsfef
so now the table looks like that

id  -   place
1  -    idms
2  -    sds
3  -   dfdf
5 -    dsfef

so where number 4 went?

i want it
0
Comment
Question by:mgtm3
8 Comments
 
LVL 9

Expert Comment

by:Rob Siklos
ID: 21746358
If you want it, then don't delete it!
0
 
LVL 9

Accepted Solution

by:
michofreiha earned 350 total points
ID: 21746387
In order to do that you should not make the id field autonumber...Put it as a number and the value of each new filed that you enter should be the greater value of id+1...This is the only solution
0
 

Author Comment

by:mgtm3
ID: 21746430
how do i do that michofreha?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 9

Expert Comment

by:michofreiha
ID: 21746484
1-change id type from autonumber to number or int and put it unique or set it as primary key for performance
2-Select max(id) from table
3-$var=max(id)+1
4-insert into table(id,place) values($var,'dsfef')

If it you don't know how to make it work I can build the complete code for you
0
 

Author Comment

by:mgtm3
ID: 21746574
thank uuuuuu
0
 
LVL 9

Expert Comment

by:michofreiha
ID: 21746584
did it work?
0
 
LVL 29

Assisted Solution

by:fibo
fibo earned 150 total points
ID: 21746629
The point is that not reusing deleted records IDs is useful in certain circumstances: that's why, if the field is "autoincrement" previous "free" values are not reused
Autoincrement does guarantee that every new record as a unique ID, which i s also unique "over time".

In most situations you don't need to worry for holes and "missing numbers": to make it short, it does not cost a cent!

So, if these homes are really a nuisance, spend some time to turn around them: the suggested solutions will be helpful for that; if they are not a nuisance... let them happen as they will!
0
 

Author Closing Comment

by:mgtm3
ID: 31465546
thankss
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question