April 3, 2006 at 6:01 pm
Is there some way of resetting identity generated number when deleting all records of the table.
In my particular case I have a table containing daily invoices, where invoice number is an integer identity field (primary key).
When the working day finishes I move all invoices to a historic table (the primary key is WorkingDate+InvoiceNumber) and delete the daily table.
I would like to start every day with the number 1 for the identity field "InvoiceNumber". I could drop an recreate the invoices table, but there must exist any other better solution.
Thanks in advance,
Felix
April 3, 2006 at 6:07 pm
If I understand this right you may be looking for..
dbcc checkident('tblName', reseed, 1)
**ASCII stupid question, get a stupid ANSI !!!**
April 3, 2006 at 6:09 pm
Did you bother to open BOL on topic "IDENTITY (property)"?
_____________
Code for TallyGenerator
April 3, 2006 at 6:55 pm
I'm sorry if I disturbed You. It was not my intention at all. In any case you replied because you wanted to.
Thanks anyway
April 3, 2006 at 6:59 pm
Not that I'm clamouring for world peace or anything but why is a basic level of amicability so hard to come by ?!?!
**ASCII stupid question, get a stupid ANSI !!!**
April 3, 2006 at 7:35 pm
Truncating the table will reset the identity number
April 3, 2006 at 7:54 pm
One should always take comments like this to be instructive, which is what it was meant to be! In any case, BOL should be your first point of call - it may even save you time by getting answers to your questions immediately.
April 3, 2006 at 8:00 pm
And what if it were a simultaneous process - what if one was scouring BOL while waiting for an answer from one of the many experts here...?!?!
**ASCII stupid question, get a stupid ANSI !!!**
April 4, 2006 at 8:50 am
Neither identity or max(n)+1 will prevent gaps. They both assume the highest value in the table is also the number of values in the table.
Instead if you want to "issue" invoice numbers to branches, simulate the old paper process. Write your table with a loop or select and then populate it with the numbers you want to use. When you issue one to a branch (or a block as mentioned by Mr. Celko), mark it as issued to that branch, or just issued, depending on your needs.
April 4, 2006 at 1:17 pm
If you are posting a solution that does not works with MS SQL Server in an MS SQL Server Forum what sense does that makes???
* Noel
April 4, 2006 at 1:46 pm
I may not have been in this field as long as you have but I don't consider myself a newbie
Your "standard" SQL 92 is not by any means the Gospel either. Can you tell how many vendors run their own extensions? ANSWER: ALL
When posting a solution that runs somewhere else than what the user requested it is absolutely of no use for the poster regardless of maintainability
* Noel
April 5, 2006 at 7:29 am
I would like to point out that this was orginally supposed to be a flamewar over being nice about suggesting that someone read the directions before asking questions.
Now this.
We finally get two for the price of one, and I didn't bring any popcorn.
April 5, 2006 at 7:35 am
well guess what...I brought the popcorn but was too rivetted to have any!!
**ASCII stupid question, get a stupid ANSI !!!**
April 5, 2006 at 8:39 am
Write a sp "EndOfDay" or update the current (I believe you use one, to transfer the data into history table) to do the following:
-After tranfser and delete the rows in the current table
-Alter the table structure
-Delete the Invoice ID column
-Insert the column again....
------------
When you 've got a hammer, everything starts to look like a nail...
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply