Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

identity column

Posted on 2007-09-30
6
Medium Priority
?
262 Views
Last Modified: 2011-10-03
I have a identity column in table A ( increment by 1).. after i truncate the records in the table, i would like to start the indentity nummber from 1 everytime.. not strting from the next number of last records that got deleted...

for example, if there are 1000 records in the table.. i would like to start the identiy number start from 1 again after deleting the table... not starting from 1001... how can i do this?
0
Comment
Question by:jung1975
6 Comments
 
LVL 19

Accepted Solution

by:
frankytee earned 800 total points
ID: 19987204
i would have thought that truncating a table would reset the counter back to 1. if it does not then drop and recreate that table.
0
 
LVL 16

Assisted Solution

by:SQL_SERVER_DBA
SQL_SERVER_DBA earned 400 total points
ID: 19987225
DELETE TABLE
SELECT * INTO <deleted_table_name>
0
 
LVL 19

Assisted Solution

by:frankytee
frankytee earned 800 total points
ID: 19987226
the below syntax
truncate table mytable
should reset the identity
if it doesn't then try
DBCC CHECKIDENT (table_name, RESEED, new_reseed_value)
where new_reseed_value = 1 for your situation
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 

Author Comment

by:jung1975
ID: 19987268
there is a foreign key relationship...so i cannot truncate table..
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 400 total points
ID: 19987804
summary from above suggestions:

--- delete all rows from the table
DELETE YOURTABLE
--- reset the identity to the next available value:
DBCC CHECKIDENT (YOURTABLE , RESEED )
0
 
LVL 8

Assisted Solution

by:matrix_aash
matrix_aash earned 400 total points
ID: 19991216
CREATE TABLE [dbo].[YOURTABLENAME](
      [IDENTITYCOLUMN] [int] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [PK_test] PRIMARY KEY CLUSTERED
(
      [autokey] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
 Please try this after you have dropped the table.

Cheers

Aash.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

810 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