I am looking to create a maintenance plan in the SQL Server Management Studio. For this maintenance plan, I need to update user accounts to a status = 0 (deactivated) after checking if the user has left the company or not.
I have already gone ahead and walked through the Maintenance plan wizard
-- Script to inactivate all users even if they are active
UPDATE USERS SET ACCOUNTSTATUS= 0 WHERE ACCOUNTSTATUS = 1
I know this is just the beginning of it, I need to create a SQL statement which will allow me to check a certain table and find if the user is not active. If they are not active, the maintenance plan will run and deactivate their account from the application.
UPDATE: The requirement for this is to also implement an Email to be sent out with the list of users that were deactivated. In order to this, I need to either create a Job that can ultimately be the same as using the Maintenance plan. What are the next steps after this? Here is the TRIGGER UPDATE which I plan to use:
CREATE TRIGGER trg_UpdateUser on dbo.USERS
AFTER UPDATE AS
BEGIN
UPDATE dbo.USERS
SET ACCOUNTSTATUS = em.ACCOUNTSTATUS
FROM dbo.USERDETAILS AS ud ()
INNER JOIN Inserted AS em
on ud.ACCOUNTSTATUS = em.ACCOUNTSTATUS
END
GO