- IF EXISTS (SELECT * FROM sys.triggers WHERE name='trigger_logindate')
- DROP TRIGGER trigger_logindate
- GO
- CREATE TRIGGER trigger_logindate ON ACCOUNT after UPDATE
- AS
- BEGIN
- IF EXISTS(SELECT 1 FROM DELETED)
- AND EXISTS (SELECT 1 FROM INSERTED)
- AND (SELECT CONVERT(VARCHAR, LAST_LOGIN_DATE, 120) FROM INSERTED)
- = CONVERT(VARCHAR, GETDATE(), 120)
- INSERT INTO LOG_LOGIN(ACCOUNT_ID, LOGIN_DATE)
- SELECT I.USER_ID, I.LAST_LOGIN_DATE
- FROM INSERTED I
- JOIN DELETED D ON I.USER_ID = D.USER_ID
- END
沒有留言:
張貼留言