Get startedGet started for free

Preventing server changes

The company is also asking you to find a method to prevent databases from being mistakenly deleted by employees.

After a detailed analysis, you decide to use a trigger to fulfill the request.

The trigger will roll back any attempts to delete databases.

This exercise is part of the course

Building and Optimizing Triggers in SQL Server

View Course

Exercise instructions

  • Create a new trigger called PreventDatabaseDelete.
  • Attach the trigger at the server level.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

-- Create a trigger to prevent database deletion
CREATE TRIGGER ___
-- Attach the trigger at the server level
ON ___ ___
FOR DROP_DATABASE
AS
   PRINT 'You are not allowed to remove existing databases.';
   ROLLBACK;
Edit and Run Code