Hi
I'm interested to know what the besrt way would be to create a sequenze
number.
How can I prevent that a number will be created twice? What are your
thoughts?
Thank's
MichelHow about using an IDENTITY column?
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006
"Michel" <michel_mueller@.bluewin.ch> wrote in message
news:usU97m5oHHA.4424@.TK2MSFTNGP03.phx.gbl...
> Hi
> I'm interested to know what the besrt way would be to create a sequenze
> number.
> How can I prevent that a number will be created twice? What are your
> thoughts?
> Thank's
> Michel
>|||The number should start from 0 and we should be able to change the number in
some years to 0 again.
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> schrieb im
Newsbeitrag news:uIxOgr5oHHA.4132@.TK2MSFTNGP02.phx.gbl...
> How about using an IDENTITY column?
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.sqlblog.com/
> http://www.aspfaq.com/5006
>
>
> "Michel" <michel_mueller@.bluewin.ch> wrote in message
> news:usU97m5oHHA.4424@.TK2MSFTNGP03.phx.gbl...
>|||Michael,
declare your column: MyKey int IDENTITY(0,1) and it will start at zero and
count by one.
TRUNCATE TABLE MyTable will clear all the data from the table and reset the
IDENTITY counter back to zero.
Thank you,
Daniel Jameson
SQL Server DBA
Children's Oncology Group
www.childrensoncologygroup.org
"Michel" <michel_mueller@.bluewin.ch> wrote in message
news:%239QX245oHHA.4032@.TK2MSFTNGP02.phx.gbl...
> The number should start from 0 and we should be able to change the number
> in some years to 0 again.
>
> "Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> schrieb im
> Newsbeitrag news:uIxOgr5oHHA.4132@.TK2MSFTNGP02.phx.gbl...
>|||> The number should start from 0
IDENTITY can start at 0.
> and we should be able to change the number in some years to 0 again.
Do you mean in combination with deleting all of the existing data? If so,
then yes, you can truncate the table (which will also reseed the identity
back to 0) or you can delete manually (which you will need to do, and in a
certain order, if other tables reference this identity value through an FK
relationship) and then use DBCC CHECKIDENT with RESEED and/or drop the table
and re-create it.
If you need to keep the existing data, please explain how anyone can
distinguish between the first row with a value of 0 and a new row when you
start over.
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006