【问题描述】
销售单保存时提示“违反了 PRIMARY KEY 约束 ‘pk_t_wm_sheet_detail’”
【问题答案】
此问题是数据库的索引和自增列出现了损坏,请备份数据库后执行以下语句:
–修复自增列语句:
use isswst6
go
declare @tablename varchar(100)
declare test_cur cursor for
select object_name(id) from syscolumns
where status=128
open test_cur
fetch test_cur into @tablename
while @@fetch_status=0
begin
DBCC CHECKIDENT (@tablename, RESEED)
fetch test_cur into @tablename
end
close test_cur
deallocate test_cur
go
—修复索引
use isswst6
go
declare @tablename varchar(100)
declare test_cur cursor for
select object_name(id) from sysobjects
where type =’U’
open test_cur
fetch test_cur into @tablename
while @@fetch_status=0
begin
DBCC DBREINDEX(@tablename)
fetch test_cur into @tablename
end
close test_cur
deallocate test_cur
go