日期:2014-05-18 浏览次数:20834 次
SET IDENTITY_INSERT 表名 on;
...新增
SET IDENTITY_INSERT 表名 off;
go
USE AdventureWorks;
GO
-- Create tool table.
CREATE TABLE dbo.Tool(
ID INT IDENTITY NOT NULL PRIMARY KEY,
Name VARCHAR(40) NOT NULL
)
GO
-- Inserting values into products table.
INSERT INTO dbo.Tool(Name) VALUES ('Screwdriver')
INSERT INTO dbo.Tool(Name) VALUES ('Hammer')
INSERT INTO dbo.Tool(Name) VALUES ('Saw')
INSERT INTO dbo.Tool(Name) VALUES ('Shovel')
GO
-- Create a gap in the identity values.
DELETE dbo.Tool
WHERE Name = 'Saw'
GO
SELECT *
FROM dbo.Tool
GO
-- Try to insert an explicit ID value of 3;
-- should return a warning.
INSERT INTO dbo.Tool (ID, Name) VALUES (3, 'Garden shovel')
GO
-- SET IDENTITY_INSERT to ON.
SET IDENTITY_INSERT dbo.Tool ON
GO
-- Try to insert an explicit ID value of 3.
INSERT INTO dbo.Tool (ID, Name) VALUES (3, 'Garden shovel')
GO
SELECT *
FROM dbo.Tool
GO
-- Drop products table.
DROP TABLE dbo.Tool
GO
------解决方案--------------------
每个数据库上用不同标示初始值
一个从 1开始
那个两个从 1亿或者10亿开始
前面还可以带个减号。
不知道这个满足你们不
------解决方案--------------------
自增列存在是有它一定道理的。在程序处理的时候取行值比较容易,而且如果设置为聚集索引,效率很高。
还有它的唯一性。当然还有N多用法。这里不一一举例了
------解决方案--------------------
谢谢分享经验