如何在SQL Server中重置身份规范 [英] How to reset identity specification in sql server

查看:78
本文介绍了如何在SQL Server中重置身份规范的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个表格ABC和列EmployeeId和薪水.
我已经设置了员工ID的身份.
并在表中将值插入为

Hi All,

I have a table ABC and Column EmployeeId and salary.
I have set identity of Employee Id.
and have inserted values in tables as

1   455454
2   45454
3   4545454
4   5656565
5   4545454



现在,如果我删除第四个记录,然后插入一个新记录,则显示为:

1 455454
2 45454
3 4545454
5 4545454
6 56565645

但我希望它不是4
1 455454
2 45454
3 4545454
4 56565645
5 4545454

请让我知道该怎么做.
谢谢你

Mohammad Wasif



Now if I delete record at no four and insert a new record then it shows as:

1 455454
2 45454
3 4545454
5 4545454
6 56565645

but I want it as no 4
1 455454
2 45454
3 4545454
4 56565645
5 4545454

Please let me know how to do it.
Thanking You

Mohammad Wasif

推荐答案

请参见 DBCC CHECKIDENT(交易记录-SQL) [^ ]


如果不想使用CHECKIDENT重新设置表的种子,请使用以下脚本插入记录.

If you do not want to reseed the table using CHECKIDENT, use the below script to insert the record.

INSERT INTO ABC (EmployeeId, Salary)
SELECT MAX(EmployeeId)+1
, [YourSalaryValue]
FROM ABC 


这篇关于如何在SQL Server中重置身份规范的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆