访问数据库时,我收到此错误:
基础提供商失败
代码:
drop table #T;
set nocount on;
create table #T (pk int identity primary key, val int);
insert into #T(val) values (2), (5), (11), (3), (7), (2), (5), (11), (3), (7);
delete t from #T t where t.val in (5, 7);
select *, ROW_NUMBER() over (order by t.pk) as rn
from #T t
order by t.pk;
declare @val int, @pk int, @rn int;
set identity_insert #T on;
DECLARE csr CURSOR FOR
select t.pk, t.val, ROW_NUMBER() over (order by t.pk) as rn
from #T t
order by t.pk;
OPEN csr
FETCH NEXT FROM csr
INTO @pk, @val, @rn;
WHILE @@FETCH_STATUS = 0
BEGIN
--select @pk as pk, @val as val, @rn as rn
if(@pk <> @rn)
begin
insert into #T(pk, val) values (@rn, @val);
delete #T where pk = @pk;
end
FETCH NEXT FROM csr
INTO @pk, @val, @rn;
END
CLOSE csr;
DEALLOCATE csr;
set identity_insert #T off;
select *
from #T t
order by t.pk;
DBCC CHECKIDENT ('#T', RESEED, @rn);
insert into #T(val) values (77);
select *
from #T t
order by t.pk;
drop table #t;
答案 0 :(得分:0)
这似乎是与数据库相关的问题,请重新检查您的权限和数据库连接字符串。