CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Building and Optimizing Triggers in SQL Server

Afficher le cours

Instructions

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

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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;
Modifier et exécuter le code