我讀了一些回答的問題,但他們不幫我! 這是我的表:重複數據表
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