YD_Event.Admin/二期需求/20260915_fix_team_result_unique_index.sql
2026-09-16 15:20:14 +08:00

37 lines
1.0 KiB
Transact-SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
修复集体项目成绩写入:EventResult 会为队内每名运动员各保留一条成绩,
因此活动成绩唯一键应为“出场记录 + 报名人员”,不能只约束出场记录。
本脚本可重复执行。
*/
SET NOCOUNT ON;
SET XACT_ABORT ON;
SET ANSI_NULLS ON;
SET ANSI_PADDING ON;
SET ANSI_WARNINGS ON;
SET ARITHABORT ON;
SET CONCAT_NULL_YIELDS_NULL ON;
SET QUOTED_IDENTIFIER ON;
SET NUMERIC_ROUNDABORT OFF;
BEGIN TRY
BEGIN TRANSACTION;
IF EXISTS (
SELECT 1
FROM sys.indexes
WHERE object_id = OBJECT_ID(N'dbo.EventResult')
AND name = N'UX_EventResult_SessionEntry_Active'
)
DROP INDEX [UX_EventResult_SessionEntry_Active] ON dbo.[EventResult];
CREATE UNIQUE NONCLUSTERED INDEX [UX_EventResult_SessionEntry_Active]
ON dbo.[EventResult]([SessionEntryId], [RegistrationPersonId])
WHERE [SessionEntryId] IS NOT NULL AND [DeleteMark] = 0;
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
THROW;
END CATCH;