数据库一直用的好好的,昨天晚上因为一些原因就删除重建,所有使用的数据都是原来的数据,只不过datafix一下,保留最初设计的时候的数据,但是在往里面加东西的时候却出现了这个问题!怪
如有高手请帮忙解决一下!
小弟先行谢过!
原来,没有出问题的数据是
数据库一直用的好好的,昨天晚上因为一些原因就删除重建,所有使用的数据都是原来的数据,只不过datafix一下,保留最初设计的时候的数据,但是在往里面加东西的时候却出现了这个问题!怪
如有高手请帮忙解决一下!
小弟先行谢过!
问题已解决,谢谢各位。下面将解决的思路说下。有什么不对的地方请指教,
CREATE TABLE [Item] (
[PID] [char] (10) COLLATE Finnish_Swedish_CI_AS NOT NULL ,
[IID] [int] NULL ,
[Index] [smallint] NOT NULL ,
[Prefix] [tinyint] NOT NULL ,
[Info] [tinyint] NOT NULL ,
[Num] [int] NOT NULL ,
[MaxEnd] [tinyint] NOT NULL ,
[CurEnd] [tinyint] NOT NULL ,
[SetGem] [tinyint] NULL ,
[XAttack] [tinyint] NULL ,
[XMagic] [tinyint] NULL ,
[XDefense] [tinyint] NULL ,
[XHit] [tinyint] NULL ,
[XDodge] [tinyint] NULL ,
[Protect] [tinyint] NULL ,
[UpgrLevel] [tinyint] NULL ,
[UpgrRate] [tinyint] NULL ,
[IID2] [int] IDENTITY (1, 1) NOT NULL
) ON [PRIMARY]
GO
以上是那个表的创建代码!
/****** Object: Stored Procedure dbo.Insert_Item Script Date: 2006-10-25 14:32:40 ******/
CREATE procedure Insert_Item
@UID int
as
declare @PID int
declare @IID int
declare @Job tinyint
select @IID = max( IID) from Item
declare Player_Cursor cursor for
select [PID] from Player where [UID] = @UID
open Player_Cursor
fetch next from Player_Cursor into @PID
while (@@FETCH_STATUS =0)
begin
select @Job = [Class] from Player where [PID] = @PID
if ( @Job = 0)
begin
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 1, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 2, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 3, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 4, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 5, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 6, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 7, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 8, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 9, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 10, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 11, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 12, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 13, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 14, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 15, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 16, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 17, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 18, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 19, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 20, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 21, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 28, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 29, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 30, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 49, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 50, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 51, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 52, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 53, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 59, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 60, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 61, 0, 8, 1, 100, 100, 0)
end -- if end
else if ( @Job = 2)
begin
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 22, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 23, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 24, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 25, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 26, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 27, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 32, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 33, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 34, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 35, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 36, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 37, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 38, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 39, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 40, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 41, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 42, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 43, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 44, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 45, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 46, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 54, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 55, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 56, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 57, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 58, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 62, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 63, 0, 8, 1, 100, 100, 0)
set @IID = @IID + 1
insert into Item (PID, IID, [Index], Prefix, Info, Num, MaxEnd, CurEnd, SetGem) values ( @PID, @IID, 64, 0, 8, 1, 100, 100, 0)
end -- else if end
fetch next from Player_Cursor into @PID
end -- while end
close Player_Cursor
deallocate Player_Cursor
GO
这个是往这个表里添加东西的时候存储过程。
根据徐强大哥的分析是往里面添加的时候iid取的是maxiid的数据,而我如果直接往里面添加东西的时候第一个是空的,所以它将自动取int数据类型的最小数,即-2147483647,所以就会产生负数,强哥给我的解决方法是,在添加数据之前插入一段iid为1的代码,那么iid在取值的时候取到的就是这个1了。而不是从-2147483647开始的。然后将iid设置成主键,所有的iid取值就会根据maxiid的数值来取了。
问题解决,谢谢大家!