Important! This is an automatic machine translated page. If you can read english, you should Click Here to read the original English version of the article.

Reset Identity Column Value in SQL Server Reset Identity stolpec Vrednost v SQL Server

If you are using an identity column on your SQL Server tables, you can set the next insert value to whatever value you want. Če uporabljate identiteta stolpec na vaši tabelah SQL Server, lahko nastavite naslednjo vrednost vstavite v karkoli vrednost, ki jo želite. An example is if you wanted to start numbering your ID column at 1000 instead of 1. Primer za to je, če si hotel začeti številčenje vaš ID stolpec na 1000 namesto 1.

It would be wise to first check what the current identify value is. To bi bilo pametno, da najprej preverite, kaj trenutno opredeliti vrednost. We can use this command to do so: Mi lahko uporabite ta ukaz, da to stori:

DBCC CHECKIDENT ('tablename', NORESEED) DBCC CHECKIDENT ( 'TABLENAME', NORESEED)

For instance, if I wanted to check the next ID value of my orders table, I could use this command: Na primer, če sem želela preveriti naslednje vrednosti ID mojih naročil tabele, sem lahko uporabite ta ukaz:

DBCC CHECKIDENT (orders, NORESEED) DBCC CHECKIDENT (naročil, NORESEED)

To set the value of the next ID to be 1000, I can use this command: Če želite nastaviti vrednosti naslednjih ID za 1000, lahko uporabite ta ukaz:

DBCC CHECKIDENT (orders, RESEED, 999) DBCC CHECKIDENT (naročil, RESEED, 999)

Note that the next value will be whatever you reseed with + 1, so in this case I set it to 999 so that the next value will be 1000. Upoštevajte, da bo naslednja vrednost karkoli reseed z + 1, tako da v tem primeru sem jo nastavite na 999, tako da bo naslednja vrednost 1000.

Another thing to note is that you may need to enclose the table name in single quotes or square brackets if you are referencing by a full path, or if your table name has spaces in it. Druga stvar je tudi omeniti, da bo morda treba priložiti ime tabele v enojnih narekovajih, ali oglatih oklepajih, če ste navajanje s celotno pot, ali če je vaše ime tabele ima prostore v njem. (which it really shouldn't) (ki ga res ne bi smelo)

DBCC CHECKIDENT ( 'databasename.dbo.orders',RESEED, 999) DBCC CHECKIDENT ( 'databasename.dbo.orders', RESEED, 999)

This article was originally written on 03/7/07 Tagged with: Ta članek je bil prvotno napisan na 03/7/07 Tagged with: Database Database , , SQL Server SQL Server

Daily Email Updates Dnevni Email Updates

You can get our how-to articles in your inbox each day for free. Lahko dobite našo kako do člankov v vašo mapo »Prejeto vsak dan brezplačno. Just enter your name and email below: Preprosto vpišite vaše ime in e-pošto spodaj:


Name: Ime:
Email: E-pošta:

Comments (15) Komentarji (15)

  1. Rukowen Rukowen

    wonderful.. čudovito ..
    That's all I need, Thanks in advanced!… To je vse, kar potrebujem, hvala napredno! ...
    Have a nice weekend.. Lep vikend ..

  2. Himani Himani

    Hey,, Hej,,
    thus is what inwas looking for.. Tako je tisto, kar inwas išče ..
    gee thankss Gee thankss

  3. kevin kevin

    thanks! hvala!

  4. Ste Ste

    Mitico! Mitico!

  5. Dominic Herard Dominic Herard

    Thanks a whole lot! Hvala celotno serijo!

  6. Nick Nick

    great concise page. zelo kratek stran. thanks. hvala. way easier than ms help files. Tako lažje kot ms datoteke s pomočjo.

  7. lakshmi Lakshmi

    This is great. To je super. But how to make the following code work: Ampak, kako narediti naslednji delovni kodo:
    declare @seqno int razglasi @ seqno int
    set @seqno = DBCC CHECKIDENT (orders, NORESEED) iz @ seqno = DBCC CHECKIDENT (naročil, NORESEED)
    DBCC CHECKIDENT ( 'databasename.dbo.orders',RESEED, @seqno) DBCC CHECKIDENT ( 'databasename.dbo.orders', RESEED, @ seqno)

  8. tdow tdow

    I created a script that will do what you want, lakshmi. Ustvaril sem scenarij, da bo to, kar hočeš, Lakshmi. Just replace MyId and mytbl below: Preprosto zamenjajte MyId in mytbl spodaj:

    DECLARE @MaxId INT IZJAVLJAM @ MaxId INT

    SELECT @MaxId = MAX( MyId ) SELECT @ MaxId = MAX (MyId)
    FROM mytbl (NOLOCK) IZ mytbl (NOLOCK)

    PRINT 'Resetting Identity value to : ' + CONVERT( VARCHAR, @MaxId ) PRINT "Ponastavitev Identity vrednost:" + CONVERT (varchar, @ MaxId)
    PRINT ” PRINT "

    DBCC CHECKIDENT ('mytbl', RESEED, @MaxId) DBCC CHECKIDENT ( 'mytbl', RESEED, @ MaxId)

    PRINT ” PRINT "

    – Verify - Preverite
    DBCC CHECKIDENT ('mytbl', NORESEED) DBCC CHECKIDENT ( 'mytbl', NORESEED)

  9. Jeff Jeff

    Thanks Geek – worked like a charm Hvala Geek - obdelan brezhibno

  10. Amit Yenurkar Amit Yenurkar

    Thanks a lot!!!!!!!!! Hvala veliko !!!!!!!!!
    Useful Stuff………… Koristne Stuff ... ... ... ...

  11. Nirman Doshi Nirman Doshi

    Thanks a lot Hvala veliko
    i was searching for this sem bil za to iskanje

  12. haridsv haridsv

    Thanks a lot. Hvala veliko. For me, if I use the value of 0 to reseed, sql server 2005 didn't start from 1, but actually from 0. Za mene, če jaz raba vrednost od 0 do reseed, SQL Server 2005, ni začela s 1., ampak dejansko od 0. May be the +1 statement is not correct? Lahko je 1 izjava ni pravilna?

  13. Prodis Prodis

    Thank you for information. Hvala za informacije. It was usefull. Bilo je koristno.

  14. Yogesh Yogesh

    Thanks Hvala :-)

  15. Ric Ric

    Brilliant, thanks Brilliant, hvala


Our Friends Naši prijatelji
Getting Started Getting Started


About How-To Geek O Kako naj Geek
What Is That Process? Kaj je to proces?
svchost.exe svchost.exe
jusched.exe jusched.exe
dwm.exe dwm.exe
ctfmon.exe Ctfmon.exe
wmpnetwk.exe wmpnetwk.exe
wmpnscfg.exe wmpnscfg.exe
rundll32.exe rundll32.exe
wfcrun32.exe wfcrun32.exe
Ipoint.exe Ipoint.exe
Itype.exe Itype.exe
Wfica32.exe Wfica32.exe
Mobsync.exe Mobsync.exe
conhost.exe conhost.exe
Dpupdchk.exe Dpupdchk.exe Adobe_Updater.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. Copyright © 2006-2009 HowToGeek.com. All Rights Reserved. All Rights Reserved.