sql server new users:
Hi, i use sql server express 2005. I defined a table "mytable" with a primary key (OrderId , type INT). I want to reseed the value of the primary key (starting with 1). The table is in a .mdf file, so i first attached it (with sql server management studio express) and then running this query: DBCC CHECKIDENT ('dbo.mytable', RESEED, 1) I get this: "checking identity information: current identity value '168', current column value '1'. DBCC execution completed. If DBCC printed error messages, contact your system administrator." But when doing: "select OrderId from dbo.mytable" the first record still starts with value 105 till 168. How to change the value of OrderId, beginning at 1 ? Thanks André
Using RESEED doesn't change the existing values. It sets the next identity value to be used. -- Tom ---------------------------------------------------- Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS SQL Server MVP Toronto, ON Canada .. [quoted text, click to view] "André" <an@dre.ty> wrote in message news:%23funRBVaHHA.1220@TK2MSFTNGP03.phx.gbl...
Hi, i use sql server express 2005. I defined a table "mytable" with a primary key (OrderId , type INT). I want to reseed the value of the primary key (starting with 1). The table is in a .mdf file, so i first attached it (with sql server management studio express) and then running this query: DBCC CHECKIDENT ('dbo.mytable', RESEED, 1) I get this: "checking identity information: current identity value '168', current column value '1'. DBCC execution completed. If DBCC printed error messages, contact your system administrator." But when doing: "select OrderId from dbo.mytable" the first record still starts with value 105 till 168. How to change the value of OrderId, beginning at 1 ? Thanks André
Hello, Steps:- 1. Using below command copy the data into a new table SELECT * INTO New_Table_name FROM Table_Name (Make sure that all data is there is new table) 2. Truncate the existing table using below command TRUNCATE TABLE Table_name 3. Issue the below command to RESEED the value in Original table DBCC CHECKIDENT ('dbo.mytable', RESEED, 1) 4. From the copied table move the data into original table. In the column list do not include Identity column. INSERT INTO Table_Name(Col2,COl2,Col3) SELECT Col2,Col3,Col4 FROM New_Table (Please do not inlcude Identity column in Insert and Select column list.) Thanks Hari [quoted text, click to view] "André" <an@dre.ty> wrote in message news:O7gMUhXaHHA.4716@TK2MSFTNGP02.phx.gbl... > Ok, thanks, but how can i change the values then? > > > "Tom Moreau" <tom@dont.spam.me.cips.ca> schreef in bericht > news:O7dJvwVaHHA.4000@TK2MSFTNGP02.phx.gbl... >> Using RESEED doesn't change the existing values. It sets the next >> identity >> value to be used. >> >> -- >> Tom >> >> ---------------------------------------------------- >> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS >> SQL Server MVP >> Toronto, ON Canada >> . >> "André" <an@dre.ty> wrote in message >> news:%23funRBVaHHA.1220@TK2MSFTNGP03.phx.gbl... >> Hi, >> >> i use sql server express 2005. I defined a table "mytable" with a primary >> key (OrderId , type INT). I want to reseed the value of the primary key >> (starting with 1). >> The table is in a .mdf file, so i first attached it (with sql server >> management studio express) and then running this query: >> DBCC CHECKIDENT ('dbo.mytable', RESEED, 1) >> >> I get this: >> "checking identity information: current identity value '168', current >> column >> value '1'. >> DBCC execution completed. If DBCC printed error messages, contact your >> system administrator." >> >> >> But when doing: "select OrderId from dbo.mytable" >> the first record still starts with value 105 till 168. >> >> >> How to change the value of OrderId, beginning at 1 ? >> >> Thanks >> André >> >> > >
Ok, thanks, but how can i change the values then? "Tom Moreau" <tom@dont.spam.me.cips.ca> schreef in bericht news:O7dJvwVaHHA.4000@TK2MSFTNGP02.phx.gbl... [quoted text, click to view] > Using RESEED doesn't change the existing values. It sets the next > identity > value to be used. > > -- > Tom > > ---------------------------------------------------- > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS > SQL Server MVP > Toronto, ON Canada > . > "André" <an@dre.ty> wrote in message > news:%23funRBVaHHA.1220@TK2MSFTNGP03.phx.gbl... > Hi, > > i use sql server express 2005. I defined a table "mytable" with a primary > key (OrderId , type INT). I want to reseed the value of the primary key > (starting with 1). > The table is in a .mdf file, so i first attached it (with sql server > management studio express) and then running this query: > DBCC CHECKIDENT ('dbo.mytable', RESEED, 1) > > I get this: > "checking identity information: current identity value '168', current > column > value '1'. > DBCC execution completed. If DBCC printed error messages, contact your > system administrator." > > > But when doing: "select OrderId from dbo.mytable" > the first record still starts with value 105 till 168. > > > How to change the value of OrderId, beginning at 1 ? > > Thanks > André > >
Great, i'll try. Thanks "Hari Prasad" <hari_prasad_k@hotmail.com> schreef in bericht news:ekqOKBYaHHA.4000@TK2MSFTNGP02.phx.gbl... [quoted text, click to view] > Hello, > > Steps:- > > 1. Using below command copy the data into a new table > > SELECT * INTO New_Table_name FROM Table_Name > > (Make sure that all data is there is new table) > > 2. Truncate the existing table using below command > > TRUNCATE TABLE Table_name > > 3. Issue the below command to RESEED the value in Original table > > DBCC CHECKIDENT ('dbo.mytable', RESEED, 1) > > 4. From the copied table move the data into original table. In the column > list do not include Identity column. > > INSERT INTO Table_Name(Col2,COl2,Col3) SELECT Col2,Col3,Col4 FROM > New_Table > > (Please do not inlcude Identity column in Insert and Select column list.) > > Thanks > Hari > > > "André" <an@dre.ty> wrote in message > news:O7gMUhXaHHA.4716@TK2MSFTNGP02.phx.gbl... >> Ok, thanks, but how can i change the values then? >> >> >> "Tom Moreau" <tom@dont.spam.me.cips.ca> schreef in bericht >> news:O7dJvwVaHHA.4000@TK2MSFTNGP02.phx.gbl... >>> Using RESEED doesn't change the existing values. It sets the next >>> identity >>> value to be used. >>> >>> -- >>> Tom >>> >>> ---------------------------------------------------- >>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS >>> SQL Server MVP >>> Toronto, ON Canada >>> . >>> "André" <an@dre.ty> wrote in message >>> news:%23funRBVaHHA.1220@TK2MSFTNGP03.phx.gbl... >>> Hi, >>> >>> i use sql server express 2005. I defined a table "mytable" with a >>> primary >>> key (OrderId , type INT). I want to reseed the value of the primary key >>> (starting with 1). >>> The table is in a .mdf file, so i first attached it (with sql server >>> management studio express) and then running this query: >>> DBCC CHECKIDENT ('dbo.mytable', RESEED, 1) >>> >>> I get this: >>> "checking identity information: current identity value '168', current >>> column >>> value '1'. >>> DBCC execution completed. If DBCC printed error messages, contact your >>> system administrator." >>> >>> >>> But when doing: "select OrderId from dbo.mytable" >>> the first record still starts with value 105 till 168. >>> >>> >>> How to change the value of OrderId, beginning at 1 ? >>> >>> Thanks >>> André >>> >>> >> >> > >
Although a reasonable reload strategy, you should know that by executing the TRUNCATE TABLE command, any IDENTITY attributes are already reseeded to their original values. You do not need to issue the DBCC CHECKIDENT function. If you only executed a DELETE <table_name> statement, then you would need to execute DBCC CHECKIDENT in order to reseed any IDENTITY attributes. Here is a got'cha for SQL Server 2000. Only members of db_ddladmin or db_owner are authorized to issue either TRUNCATE TABLE or DBCC CHECKIDENT although anyone can be granted DELETE <table_name> rights, which ends up being sort of redundant. For SQL Server 2005, you can grant those special permissions without making users full members of either of those default roles. So why would one want to issue the DELETE + DBCC CHECKIDENT combination instead of TRUNCATE TABLE? Because DELETE is fully logged, where TRUNCATE TABLE only logs the metadata page deallocation actions. So, it depends on what sort of transaction logging you want to maintain. Although, there may be equally valuable alternative reasons; I just can't come up with any others at the moment. Sincerely, Anthony Thomas -- [quoted text, click to view] "Hari Prasad" <hari_prasad_k@hotmail.com> wrote in message news:ekqOKBYaHHA.4000@TK2MSFTNGP02.phx.gbl... > Hello, > > Steps:- > > 1. Using below command copy the data into a new table > > SELECT * INTO New_Table_name FROM Table_Name > > (Make sure that all data is there is new table) > > 2. Truncate the existing table using below command > > TRUNCATE TABLE Table_name > > 3. Issue the below command to RESEED the value in Original table > > DBCC CHECKIDENT ('dbo.mytable', RESEED, 1) > > 4. From the copied table move the data into original table. In the column > list do not include Identity column. > > INSERT INTO Table_Name(Col2,COl2,Col3) SELECT Col2,Col3,Col4 FROM New_Table > > (Please do not inlcude Identity column in Insert and Select column list.) > > Thanks > Hari > > > "André" <an@dre.ty> wrote in message > news:O7gMUhXaHHA.4716@TK2MSFTNGP02.phx.gbl... > > Ok, thanks, but how can i change the values then? > > > > > > "Tom Moreau" <tom@dont.spam.me.cips.ca> schreef in bericht > > news:O7dJvwVaHHA.4000@TK2MSFTNGP02.phx.gbl... > >> Using RESEED doesn't change the existing values. It sets the next > >> identity > >> value to be used. > >> > >> -- > >> Tom > >> > >> ---------------------------------------------------- > >> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS > >> SQL Server MVP > >> Toronto, ON Canada > >> . > >> "André" <an@dre.ty> wrote in message > >> news:%23funRBVaHHA.1220@TK2MSFTNGP03.phx.gbl... > >> Hi, > >> > >> i use sql server express 2005. I defined a table "mytable" with a primary > >> key (OrderId , type INT). I want to reseed the value of the primary key > >> (starting with 1). > >> The table is in a .mdf file, so i first attached it (with sql server > >> management studio express) and then running this query: > >> DBCC CHECKIDENT ('dbo.mytable', RESEED, 1) > >> > >> I get this: > >> "checking identity information: current identity value '168', current > >> column > >> value '1'. > >> DBCC execution completed. If DBCC printed error messages, contact your > >> system administrator." > >> > >> > >> But when doing: "select OrderId from dbo.mytable" > >> the first record still starts with value 105 till 168. > >> > >> > >> How to change the value of OrderId, beginning at 1 ? > >> > >> Thanks > >> André > >> > >> > > > > > >
Don't see what you're looking for? Try a search.
|