标签:
使用分区来将非自增表改为自增表
------------------------------------------------- --创建测试表TestTable001和TestTable002 CREATE TABLE TestTable001 ( ID INT PRIMARY KEY, C1 VARCHAR(200) ) GO CREATE TABLE TestTable002 ( ID INT IDENTITY PRIMARY KEY, C1 VARCHAR(200) ) GO --向测试表TestTable001插入数据 INSERT INTO TestTable001 SELECT ROW_NUMBER() OVER (ORDER BY object_id) AS RID, name FROM SYS.all_objects GO ------------------------------------------------- --将分区表切换来将TestTable001换入到TestTable002中 ALTER TABLE TestTable001 SWITCH PARTITION 1 TO TestTable002 --使用RESEED重置自增值 DBCC CHECKIDENT(‘TestTable002‘,RESEED) --查看当前表中自增值 SELECT IDENT_CURRENT(‘TestTable002‘) ------------------------------------------------- --插入测试 INSERT INTO TestTable002(C1) SELECT ‘Test‘ --查看上一次插入的自增ID SELECT @@IDENTITY
--=========================================
妹子来啦
标签:
原文地址:http://www.cnblogs.com/TeyGao/p/5201706.html