By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,378 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,378 IT Pros & Developers. It's quick & easy.

SQL Query IDENTITY Row Reset Help

P: 1
I am trying to reset an IDENTITY RowNumber
back to 1 in a query when the Person's Name is the same. The following query
can be used agains the pubs database in SQL Server.

I am trying to figure out where to place the section for the DBCC CHECKIDENT item in order to reset the RowNumber back to 1 when ever the lname column is the same. For example if the pub database had duplicate records for a given employee the RowNumber would reset back to 1.

RowNumber int IDENTITY (1, 1),
emp_id char(9) )
--DECLARE @seed int
--SET @seed = 1

INSERT #RowNumber (emp_id)
SELECT emp_id
FROM employee
ORDER BY lname
SELECT RowNumber, e.emp_id, lname, fname, job_id
FROM #RowNumber r JOIN employee e
ON r.emp_id = e.emp_id

ORDER BY RowNumber
Mar 29 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.