在“插入到表值()”中处理标识列声明? [英] Handling identity columns in an "Insert Into TABLE Values()" statement?

查看:174
本文介绍了在“插入到表值()”中处理标识列声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SQL Server 2000或更高版本中,在使用如下语句时,还是要处理自动生成的主键(标识)列?

In SQL Server 2000 or above is there anyway to handle an auto generated primary key (identity) column when using a statement like the following?

Insert Into TableName Values(?, ?, ?)

我的目标是

推荐答案

默认情况下,如果您有一个标识列, em>需要在VALUES部分指定它。如果您的表格为:

By default, if you have an identity column, you do not need to specify it in the VALUES section. If your table is:

ID    NAME    ADDRESS

然后你可以:

INSERT INTO MyTbl VALUES ('Joe', '123 State Street, Boston, MA')

这将自动为您生成ID,不必考虑它。如果您 SET IDENTITY_INSERT MyTbl ON ,您可以为ID列分配一个值。

This will auto-generate the ID for you, and you don't have to think about it at all. If you SET IDENTITY_INSERT MyTbl ON, you can assign a value to the ID column.

这篇关于在“插入到表值()”中处理标识列声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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