28-5-2011 16:42:34
Mình dùng 1 store pro.. để insert del repair nhưng khi mình cho dòng
"DBCC CHECKIDENT ('tgdGroupIDID', RESEED, 1)" để reset lại trường id tự tăng thì nó báo lỗi
Checking identity information: current identity value '19', current column value '18'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Msg 2627, Level 14, State 1, Procedure StoretgdGroupIDID, Line 15
Violation of PRIMARY KEY constraint 'PK_tgdGroupIDID'. Cannot insert duplicate key in object 'dbo.tgdGroupIDID'.
The statement has been terminated.
Còn nếu ko cho vào thì chạy Bình thường.Nhưng mình muốn reset khóa chính id tự động tăng có anh em Giúp mình với?.dưới đây là proc....
USE [DBGDnongsan]
GO
/****** Object: StoredProcedure [dbo].[StoretgdGroupIDID] Script Date: 05/28/2011 16:24:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[StoretgdGroupIDID](
@mode int,
@id int,
@idGroup int,
@nameGroup nvarchar(50)=null,
@ddescription nvarchar(150)=null,
@icon nvarchar(50)=null
)
as
if(@mode = 1) --Them
begin
DBCC CHECKIDENT ('tgdGroupIDID', RESEED, 1)
INSERT INTO tgdGroupIDID VALUES(@idGroup,@nameGroup,@ddescription,@icon)
end
if(@mode = 0) --Sua
begin
if exists(select * from tgdGroupIDID where id = @id)
begin
update tgdGroupIDID set idGroup= @idGroup,nameGroup=@nameGroup,description=@ddescription,icon=@icon where id = @id
end
end
if(@mode =-1) --Xoa
begin
delete from tgdGroupIDID where id = @id
end