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

  • SEARCH
  • Home
  • 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 6095873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:51:41+00:00 2026-05-23T12:51:41+00:00

In Sql Server 2005, I have two databases. In the first one I have

  • 0

In Sql Server 2005, I have two databases. In the first one I have a table like this:

CREATE TABLE [dbo].[SG](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [sgName] [nvarchar](50) NOT NULL,
    [active] [bit] NOT NULL,
    [hiddenf] [int] NOT NULL
)

In the second, I have a view like this:

CREATE VIEW [dbo].[SG] AS   
    SELECT id,sgName, active 
    FROM [FirstDatabase].dbo.SG WHERE hiddenf = 1

with a trigger like this:

CREATE TRIGGER [dbo].[InsteadTriggerSG] on [dbo].[SG] 
INSTEAD OF INSERT AS BEGIN 
   INSERT INTO [FirstDatabase].dbo.SG(sgName,active,hiddenf)
   SELECT sgName,COALESCE (active,0), 1 FROM inserted 
END

When I insert into the view:

using (SqlConnection connection = new SqlConnection(
               connectionString))
{
   SqlCommand command = new SqlCommand("INSERT INTO SG(sgName, active) VALUES('Test', 1)", connection);
   var affectedRows = command.ExecuteNonQuery();
   Assert.AreEqual(1, affectedRows);
}

I get affectedRows equal to two, while my expected value is 1.

  • 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-23T12:51:42+00:00Added an answer on May 23, 2026 at 12:51 pm

    This sort of question usually makes me think “triggers”.

    I have just created an exact copy of your scenario (thanks for the detailed instructions) and I am kind of seeing similar results.

    By kind of, I meant that when I execute the insert, SSMS outputs

    (1 row(s) affected)

    (1 row(s) affected)

    but when I checked the original database, only one row had been added.

    To solve your problem, do this:

    ALTER TRIGGER [dbo].[InsteadTriggerSG] on [dbo].[SG] 
    INSTEAD OF INSERT AS BEGIN 
       SET NOCOUNT ON -- adding this in stops it from reporting from in here
       INSERT INTO [TEST].dbo.SG(sgName,active,hiddenf)
       SELECT sgName,COALESCE (active,0), 1 FROM inserted 
    END
    

    The issue is that both the trigger and the actual table on the original database are reporting that they’ve updated a row. If you remove this reporting from the trigger, but leave it in the original database, you will always get a true answer, whether you update via the view or straight into the original table directly.

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

Sidebar

Related Questions

I have two SQL Server 2005 databases, one is for development and the other
I have two servers, the first one with SQL Server 2005 and the second
sql server 2005 : i have a column empid in employee table with identity
Basically I have a two databases on SQL Server 2005. I want to take
I have two databases DB_OLD and DB_NEW, both on SQL Server 2005, and I
We have two tables in a SQL Server 2005 database, A and B.There is
Good Afternoon All, I have two tables in my SQL Server 2005 DB, Main
In SQL Server 2005 I have an id field in a table that has
[using SQL Server 2005] I have a table full of users, I want to
I want to create a list of columns in SQL Server 2005 that have

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.