我读了一些回答的问题,但他们不帮我! 这是我的表:重复数据表
CREATE TABLE [dbo].[t_status](
[student_id] [nvarchar](50) NOT NULL,
[les_id] [int] NOT NULL,
[year_id] [int] NOT NULL,
[status] [bit] NULL,
[Number_of_fail] [int] NULL,
我要防止重复数据,如果他们student_id数据和les_id都是平等的。 我该怎么做, 我没有关于触发器的很多信息,但我试过这个没有用的!
ALTER TRIGGER Trigger1
ON dbo.t_status
FOR INSERT
AS
declare @stu_id nvarchar(50)
declare @les_id int
Declare @Count int
select @stu_id=student_id,@les_id = les_id From inserted
Select @Count=Count(student_id) From t_status where [email protected]_id and [email protected]_id
group by student_id
if @Count>1
delete From t_status where student_id [email protected]_id
student_id和les_id上的复合主键? – dngfng