我在SQL Server中有TRIGGER错误

时间:2016-05-04 20:38:53

标签: sql sql-server

我有一个表ID, NAME, BIRTHDAYNAME),我想使用触发器来约束输入数据,不允许CREATE TRIGGER TEST ON STUDENTS FOR INSERT AS BEGIN IF EXISTS (SELECT * FROM inserted WHERE NAME IN (SELECT NAME FROM STUDENTS)) BEGIN PRINT 'Duplicated' ROLLBACK TRANSACTION END END 列重复的输入数据

CREATE TRIGGER TEST
ON STUDENTS
FOR INSERT
AS 
BEGIN
    DECLARE @NAME nvarchar(15)

    SELECT @NAME = NAME
    FROM inserted

    IF EXISTS (SELECT * FROM STUDENTS WHERE NAME = @NAME)
    BEGIN
        PRINT 'Duplicated'
        ROLLBACK TRAN
    END
END

以及更多

my $len = $seq->length();
if($len < 20 || $len > 120){
    $count++;
}

但是,上面的2方法,虽然输入数据不重复,但它的返回错误是“重复”。我不知道哪里出错,我认为是因为'EXISTS'

帮助我,非常感谢^ _ ^

0 个答案:

没有答案