【发布时间】:2011-10-07 12:15:13
【问题描述】:
对于 MySQL here 提出了同样的问题,无论如何该语法在 SQL Server 中不起作用。
我在此处粘贴该问题的示例(通过简化它),因为它很好地解释了我需要什么。
DECLARE @t1 integer
SET @t1=0;
-- MyTable is a simple Table with 2 fields "MyID" and "MyValue"
insert into MyTable
SELECT @t1 := @t1+1, --this "should" work in MySQL
MyAnotherValue
FROM AnotherTable
有没有办法在 SQL Server 中实现相同的功能(不使用游标)?
注意:这是一个运行一次的查询,它是一个维护查询,所以竞争条件和锁不是问题。
【问题讨论】:
标签: sql-server sql-server-2008 auto-increment