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 6577471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:38:23+00:00 2026-05-25T15:38:23+00:00

I am a new in ms sql server and faced with the problem: i

  • 0

I am a new in ms sql server and faced with the problem: i can’t drop a trigger in the database that is external to my current database.

So, I have 2 databases -CRM (main) and CrmHistory(where the history information is held).
In CrmHistory database I am writing some API to manage the gathering of the history information.
One of the task is to create\drop triggers in Crm database.
Here is my SP:

create procedure [dbo].[DropHistoryTriggers]    
as
begin

set nocount on;

 declare @sql table(s varchar(1000), id int identity)
 declare @SqlStr nvarchar(max)=''       

 insert into @sql(s)
   select 'drop trigger '+  name from Crm.sys.triggers 
    where name like '%History' 

select @SqlStr=@SqlStr+s+' ' +char(13) from @sql

if (@SqlStr!='')
execute (@SqlStr)

end

While executing it, I get “Cannot drop the trigger ‘trndshistory’, because it does not exist or you do not have permission.”

Both databases is owned by ‘sa’.I create and execute SP also using ‘sa’ login.

How I tried to solve this issue:

  1. Set the TRUSTWORTHY property to ON on both databases.
  2. When I specified “with execute of owner\sa\self” I got the same error.
  3. I created another login, then create 2 users mapping to this login in both databases and granted AUTHENTICATE in the target database. Then I specified “execute as” in SP to impersonate this user.It doesn’t help me, to.
  • 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-05-25T15:38:24+00:00Added an answer on May 25, 2026 at 3:38 pm

    The problem is that you are pulling the triggers from a catalog view in the database crm, but then trying to drop them from the current database. To execute in the context of the other database, you can use:

    EXEC crm.dbo.sp_executesql @SqlStr;
    

    As an aside, probably much easier to do this without a @table at all (uncomment the EXEC line when you are confident it is doing what it should):

    CREATE PROCEDURE [dbo].[DropHistoryTriggers]    
    AS
    BEGIN
        SET NOCOUNT ON;
    
        DECLARE @sql NVARCHAR(MAX) = N'';
    
        SELECT @sql += 'DROP TRIGGER ' 
            + QUOTENAME(t.name) + ';' + CHAR(13)
            FROM crm.sys.triggers AS t
            WHERE t.name LIKE '%History';
    
        PRINT @sql;
        --EXEC crm.dbo.sp_executesql @sql;
    END
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using SQL Server 2005. I have a site that people can vote
How can I create a new SQL Server Compact database file (.sdf) programmatically, without
I have a large (~ 40gb ) SQL Server 2008 database that I would
I am creating a new SQL Server 2008 database. I have two two tables
Question: The new SQL Server 2008 database returns me values formatted English (date/float). Is
I'm loading a SQL Server 2000 database into my new SQL Server 2005 instance
I need to create an entirely new Sql Server 2008 database and want to
I am new to SQL Server, and I have been tasked with setting permissions
I'm brand new to SQL Server 2008, and have some newbie questions about the
I am pretty much new to using SQL Server 2000. I have been using

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.