How can I script the creation of a new SQL Login (whether by Windows
Authentication or with SQL password) and have it automatically expire after some
time, e.g. 8 hours, 24 hours
I’ve tried searching here in stackoverflow but I haven’t found a solution. If you guys know of one that exists here, please let me know too. Thank you.
I am using SQL Server 2005 and 2008
First create a table to store the auto-expiring logins
Create a SERVER LEVEL LOGON trigger to capture and block the special logins. Notice that I am specially testing for the prefix
XPRas a convention, because if you get a LOGON trigger wrong, it’s inconvenient to fix.When you need to create new logins, remember to insert a record into the table.