Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8814859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:14:02+00:00 2026-06-14T04:14:02+00:00

How can admin prevent himself to drop or truncate specific tables, because sometimes a

  • 0

How can admin prevent himself to drop or truncate specific tables, because sometimes a table is accidently truncated or deleted, making view is not a good idea. if i make a trigger ,it is implemented in all tables in db. i just want to implement it in specific tables, in sql server ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:14:04+00:00Added an answer on June 14, 2026 at 4:14 am
    Create TRIGGER [TR_ProtectCriticalTables]
    ON DATABASE 
    FOR 
    DROP_TABLE
    
    AS    
    DECLARE @eventData XML,
        @uname NVARCHAR(50),
        @oname NVARCHAR(100),
        @otext VARCHAR(MAX),
        @etype NVARCHAR(100),
        @edate DATETIME
    SET @eventData = eventdata()
    SELECT
        @edate=GETDATE(),
        @uname=@eventData.value('data(/EVENT_INSTANCE/UserName)[1]', 'SYSNAME'),
        @oname=@eventData.value('data(/EVENT_INSTANCE/ObjectName)[1]', 'SYSNAME'),
        @otext=@eventData.value('data(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]', 
                'VARCHAR(MAX)'),
        @etype=@eventData.value('data(/EVENT_INSTANCE/EventType)[1]', 'nvarchar(100)')
      IF @oname IN ('tbluser')-- You can give comma seperated list here
    BEGIN
    DECLARE @err varchar(100)
    SET @err = 'Table ' + @oname  + ' is super duper protected and cannot be dropped.'
    RAISERROR (@err, 16, 1) ;
    ROLLBACK;
    END
    GO
    ENABLE TRIGGER [TR_ProtectCriticalTables] ON DATABASE 
    

    For disabling the truncate try this

    EXEC sys.sp_cdc_enable_table
    @source_schema = N'dbo',
    @source_name = N'TestTable',
    @role_name = NULL
    GO
    

    This may cause some other problems so please check before using.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if I use transactions, will it lock the tables and prevent it from making
Can you prevent a user with project admin or project collection admin rights from
Hi Experts How I can prevent database user deleting any data in tables using
Can Django admin site select entries by a custom date range, i.e. using two
i got a page where the admin can edit some photos i pull from
I have a set of checkboxes that an Admin can tick to give users
I'm currently working on an admin section for a website. The admin can use
how can I modify admin generated modules (acions and templates)? They are stored in
how can i set default value in sonata admin bundle the data option is
I know you can invite friends to your Facebook Fan Page via Admin Panel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.