0

トリガーに関する HW 割り当ての学習に取り組んでおり、次のように DML ForTriggers の挿入と削除の両方で構文に問題があります。

CREATE TRIGGER tr_PERSON_ForInsert
ON PERSON
FOR INSERT
AS
BEGIN

    DECLARE @SSN  CHAR(9)
    SELECT  @SSN  = SSN FROM  inserted
    DECLARE @NAME VARCHAR(50)
    SELECT  @NAME = NAME FROM inserted  
    DECLARE @USERNAME VARCHAR(50)
    SELECT  @USERNAME USERNAME FROM INSERTED
    declare @time time(7)
    select  @time = time from inserted

    insert into PERSON_DEL_LOG
    VALUES ('New person with SSN = ' +
    Cast(@SSN as NVARchar(9)) + 
    CAST(@NAME AS NVARCHAR(50)) +
    cast(@username as nvarchar(50)) +
    cast(@time as nvarchar(20))
    )
END

INSERT INTO PERSON('012675543', 'MIKE', '5467896543', 'MUSEUM', 'INTEL', 
'BLUECROSS', '987654321')

CREATE TRIGGER tr_PERSON_ForDELETE
ON PERSON
FOR DELETE
AS
BEGIN

    DECLARE @SSN  CHAR(9)
    SELECT  @SSN  = SSN FROM  DELETED
    DECLARE @NAME VARCHAR(50)
    SELECT  @NAME = NAME FROM DELETED       

    insert into PERSON_DEL_LOG
    VALUES ('New person with SSN = ' +
    Cast(@SSN as nvarchar(9)) +
    Cast(@NAME as VARCHAR(50)) + 'is added at ' + 
    cast(Getdate() as nvarchar(20))
    )
END

DELETE FROM PERSON WHERE NAME = 987654321

SELECT * FROM PERSON_DEL_LOG

PERSON_DEL_LOGのテーブル構造:

SSN, NAME, USERNAME, TIME

私の問題がどこにあるのかを正確に知る必要があります

4

0 に答える 0