假设所有列都必须匹配重复 - 那么你会使用这样的东西:
CREATE PROCEDURE dbo.InsertNewRow
@AgendaId uniqueidentifier.,
@MatirelId int, -- you did not mention what *types* those columns have - adapt as needed!
@InstructorId int,
@ClassId int,
@AddedDate datetime,
@Semester int
@StartTime time(7),
@EndTime time(7),
@DaySchedule int
AS BEGIN
IF EXISTS (SELECT * FROM dbo.Agenda
WHERE MatirelId = @MatirelId
AND InstructorId = @InstructorId
AND ClassId = @ClassId
AND Semester = @Semester
AND StartTime = @StartTime
AND EndTime = @EndTime
AND DaySchedule = @DaySchedule)
RAISERROR .......
RETURN
INSERT INTO dbo.Agenda(AgendaId, MatirelId, InstructorId, ClassId,
AddedDate, Semester, StartTime, EndTime, DaySchedule)
VALUES(@AgendaId, @MatirelId, @InstructorId, @ClassId,
@AddedDate, @Semester, @StartTime, @EndTime, @DaySchedule)
END
阅读优秀的 MSDN 文档,了解如何准确调用RAISERROR
以从存储过程中引发错误!