DBCC CHECKIDENT
功能描述
DBCC CHECKIDENT用于对标识列进行获取或者重置功能。
注意事项
- 对标识列进行获取需要有表的select权限,对标识列执行重置需要有表的update权限。
语法格式
1. DBCC CHECKIDENT (table_name [ , { NORESEED | { RESEED [ , new_reseed_value ] } } ] ) [ WITH NO_INFOMSGS ]
参数说明
- table_name
表名,表中必须要有标识列。 - NORESEED
指定仅做标识列的查询,不对标识列进行修改。 - RESEED
指定应该对标识列进行修改。如果既不声明为RESEED,也不声明为NORESEED,默认为RESSED操作。 - new_reseed_value
用作标识列的当前值的新值,默认值为选取标识列的当前标识值和当前标识列的最大值之间较大值。 - WITH NO_INFOMSGS
取消显示所有信息性消息。
示例
1. openGauss=# CREATE TABLE Employees (EmployeeID serial ,Name VARCHAR(100) NOT NULL);
2. NOTICE: CREATE TABLE will create implicit sequence "employees_employeeid_seq" for serial column "employees.employeeid"
3. CREATE TABLE
4. openGauss=# insert into Employees(Name) values ('zhangsan');
5. INSERT 0 1
6. openGauss=# insert into Employees(Name) values ('lisi');
7. INSERT 0 1
8. openGauss=# insert into Employees(Name) values ('wangwu');
9. INSERT 0 1
10. openGauss=# insert into Employees(Name) values ('heliu');
11. INSERT 0 1
12. openGauss=# DBCC CHECKIDENT ('Employees', NORESEED);
13. NOTICE: "Checking identity information: current identity value '4', current column value '4'."
14. CONTEXT: referenced column: dbcc_check_ident_no_reseed
15. dbcc_check_ident_no_reseed
16. --------------------------------------------------------------------------------------
17. Checking identity information: current identity value '4', current column value '4'.
18. (1 row)
20. openGauss=# DBCC CHECKIDENT ('Employees', RESEED, 10);
21. NOTICE: "Checking identity information: current identity value '4'."
22. CONTEXT: referenced column: dbcc_check_ident_reseed
23. dbcc_check_ident_reseed
24. ------------------------------------------------------------
25. Checking identity information: current identity value '4'.
26. (1 row)
28. openGauss=# DBCC CHECKIDENT ('Employees', NORESEED);
29. NOTICE: "Checking identity information: current identity value '10', current column value '4'."
30. CONTEXT: referenced column: dbcc_check_ident_no_reseed
31. dbcc_check_ident_no_reseed
32. ---------------------------------------------------------------------------------------
33. Checking identity information: current identity value '10', current column value '4'.
34. (1 row)
