Database Trigger Sample - SQL Server

The following database trigger will allow the MyUser user to login only from the MyWebServer machine.

if exists (select 2 from sys.server_triggers where name = N'logon_test_trigger')
    drop trigger logon_test_trigger on all server
go
CREATE TRIGGER logon_test_trigger
ON ALL SERVER WITH EXECUTE AS 'sa' FOR LOGON AS
BEGIN

    /* Within a logon trigger, ROLLBACK will cancel/disable the logon */

    IF ORIGINAL_LOGIN() = 'MyUser' 
    AND UPPER(HOST_NAME()) <> 'MYWEBSERVER'

        ROLLBACK; 

END