将表的列更新为序列
我想使用存储过程的结果更新表的列,但
create procedure seq
as
DECLARE @NextValue INT;
INSERT SequencesTable DEFAULT VALUES;
DELETE SequencesTable WITH(READPAST);
SELECT SCOPE_IDENTITY();
go
我无法使用 UDF,因为它是不确定的。 这样的事情是行不通的,
UPDATE [dbo].[t1] SET [c1] = seq
我有一种感觉,我正在以错误的方式处理这个问题。
我只想更新一个看起来像这样的表
1 1
2 2
1 4
1 4
5 5
1 2
看起来像这样
1 1
2 2
3 4
4 4
5 5
6 2
I want to update a table's column using the results of a stored procedure
create procedure seq
as
DECLARE @NextValue INT;
INSERT SequencesTable DEFAULT VALUES;
DELETE SequencesTable WITH(READPAST);
SELECT SCOPE_IDENTITY();
go
I can't use a UDF since it is nodeterministic. Something like this won't work
UPDATE [dbo].[t1] SET [c1] = seq
I have a feeling I am approaching this the wrong way.
I just want to do update a table that looks like this
1 1
2 2
1 4
1 4
5 5
1 2
To look like this
1 1
2 2
3 4
4 4
5 5
6 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的操作:
尝试内部查询,直到得到您喜欢的内容,然后应用更新。
NULLIF(c1,c1) 尝试保留磁盘上的原始顺序。 它总是返回 null。
Try something like this:
Play around with the inner query until you get something you like, then apply the update.
The NULLIF(c1,c1) attempts to preserve original order on disk. It always returns null.