如何在SQL Server 2005中插入标识列值 [英] How do I insert Identity column value in SQL Server 2005

查看:86
本文介绍了如何在SQL Server 2005中插入标识列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Microsoft SQL Server 2005中设计了一个表,该表只有两列,并且这两列都是标识字段.第一列的标识值从1开始,第二列的标识值从1001开始.我将在此表中插入1000条记录.

I have designed a table in Microsoft SQL Server 2005 it has only two columns and both columns are identity fields. First column''s identity value start from 1 and second column identity value start from 1001. I will insert 1000 records in this table. How do I can do this?

推荐答案

1-您不能在表上拥有2个身份密钥.

2-如果您有1个标识列,并且要插入1000条记录,则可以执行以下操作.

1- You can''t have 2 identity key on a table.

2- If you have 1 identity column and you want to insert 1000 records you can do like following.

DECLARE @Counter int
SET @Counter=1
WHILE (@Counter) <= 1000
BEGIN
	-- Wrtie your insert statement here
	SET @Counter = @Counter +1

end



3-如果在这种情况下,如果您的表具有1列类型标识,则可以添加如下所示的行.



3- If you have a table having 1 column of type identity in that case you can add a row like following.

INSERT INTO TABLE_NAME DEFAULT VALUES


这篇关于如何在SQL Server 2005中插入标识列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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