SQL Server 2000之identity
来源:互联网 发布:域名还要备案吗 编辑:程序博客网 时间:2024/05/16 17:06
CREATE TABLE products (id int IDENTITY PRIMARY KEY, product varchar(40))
GO
GO
如果
INSERT INTO products (id, product) VALUES(3, 'garden shovel')
GO
GO
就会报错
Server: Msg 544, Level 16, State 1, Line 1
Cannot insert explicit value for identity column in table 'products' when IDENTITY_INSERT is set to OFF.
Cannot insert explicit value for identity column in table 'products' when IDENTITY_INSERT is set to OFF.
如何解决:
SET IDENTITY_INSERT products ON
完整code:
-- Create products table.CREATE TABLE products (id int IDENTITY PRIMARY KEY, product varchar(40))GO-- Inserting values into products table.INSERT INTO products (product) VALUES ('screwdriver')INSERT INTO products (product) VALUES ('hammer')INSERT INTO products (product) VALUES ('saw')INSERT INTO products (product) VALUES ('shovel')GO-- Create a gap in the identity values.DELETE products WHERE product = 'saw'GOSELECT * FROM productsGO-- Attempt to insert an explicit ID value of 3;-- should return a warning.INSERT INTO products (id, product) VALUES(3, 'garden shovel')GO-- SET IDENTITY_INSERT to ON.SET IDENTITY_INSERT products ONGO-- Attempt to insert an explicit ID value of 3INSERT INTO products (id, product) VALUES(3, 'garden shovel').GOSELECT * FROM productsGO-- Drop products table.DROP TABLE productsGO
更多可参考:http://blog.csdn.net/seabluecn/archive/2007/10/19/1833173.aspx
- SQL Server 2000之identity
- sql server 重置 identity
- SQL SERVER identity
- SQL Server -identity列
- SQL Server IDENTITY用法
- SQL Server 中的identity
- SQL SERVER 中identity
- SQL Server 学习笔记之IDENTITY(属性)(Transact-SQL)
- Sql Server identity VS uniqueidentifier
- SQL Server 2000中,SCOPE_IDENTITY、IDENT_CURRENT 和 @@IDENTITY
- Sql server identity字段的重新定位...
- 解析SQL Server identity列的操作方法
- 解析SQL Server identity列的操作方法
- SQL SERVER里@@identity 的用法
- SQL Server 的IDENTITY(属性)
- Sql Server Table 中identity 重置...
- MS SQL Server 自增(Identity)主鍵重複
- sql server 2005 identity 标识列小结
- .NET Mobile Develop
- sysHotel On Line Remote File Disclosure Vulnerability
- ASP.NET2.0数据操作之母板页和站点导航
- ASP.NET 数据绑定常用代码
- .htaccess 文件.htaccess 文件
- SQL Server 2000之identity
- 关于我自己
- Web下的整体测试
- Eval数据绑定语法绑定Image、Label和HyperLink控件
- aspx网页以HTML形式存储的几个方法
- 利用ASP上传漏洞得到webshell实战
- 什么叫软件测试?
- 检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败解决方法
- 闰年的定义