---
title: "what are DDL Triggers? Create a trigger to prevent a user to delete a table in the database."  
description: "what are DDL Triggers? Create a trigger to prevent a user to delete a table in the database."  
author: "Ashutosh Patel"  
published: 2023-03-22  
updated: 2023-03-30  
canonical: https://www.mindstick.com/forum/157515/what-are-ddl-triggers-create-a-trigger-to-prevent-a-user-to-delete-a-table-in-the-database  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 1 minute  

---

# what are DDL Triggers? Create a trigger to prevent a user to delete a table in the database.

what are [DDL](https://www.mindstick.com/interview/23007/ddl-vs-dml) [Triggers](https://www.mindstick.com/articles/337000/what-are-sql-triggers-and-ways-of-using-them-effectively)? Create a [trigger](https://www.mindstick.com/blog/167/triggers-in-wpf) to prevent a [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) to [delete](https://www.mindstick.com/forum/33620/how-to-delete-record-from-list-in-mvc-using-ajax) a [table in the database](https://www.mindstick.com/forum/156738/how-to-add-and-remove-columns-from-an-existing-table-in-the-database).

## Replies

### Reply by Krishnapriya Rajeev

Data Definition Language (DDL) triggers are fired in response to events caused by DDL statements like CREATE, ALTER, and DROP. These can be created at either the database level or server level, and can also be triggered by system-defined stored procedures that execute actions similar to DDL statements.

These triggers are helpful because:

1. sometimes it is necessary to avoid altering the database schema.\
2. sometimes it is necessary to review database schema modifications.\
3. sometimes we must respond to a modification made in the database schema.

An example of a DDL trigger that prevents the user from deleting a [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) in a database would be as follows:

```plaintext
CREATE TRIGGER PreventDrop
ON DATABASE
FOR DROP_TABLE
AS
PRINT 'Error: Table cannot be dropped!'
ROLLBACK
;
```


---

Original Source: https://www.mindstick.com/forum/157515/what-are-ddl-triggers-create-a-trigger-to-prevent-a-user-to-delete-a-table-in-the-database

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
