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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:03:38+00:00 2026-06-09T17:03:38+00:00

Recently I inherited a new ASP web application that merely allows customers to pay

  • 0

Recently I inherited a new ASP web application that merely allows customers to pay their outstanding invoices online. The application was poorly designed and did not have a payment history table. The entire payments table was deleted by the web service that transports the payment records to the accounting system of record.

I just created a simple trigger on the Payments table that simply copies the data from the Payments table into a Payment_Log table. Initially, the trigger just did a select * on inserted to copy the data. However, I just modified the trigger to insert the date of the payment into the Payment_Log table since one of our customers is having some issues that I need to debug. The new trigger is below. My question is that I have noticed that with this new version of the trigger, the rows are being inserted into the middle of the table (i.e. not at the end). Can someone explain why this is happening?

ALTER trigger [dbo].[PaymentHistory] on [dbo].[Payments]
for insert as

Declare @InvoiceNo nvarchar(255),
    @CustomerName nvarchar(255),
    @PaymentAmount float,
    @PaymentRefNumber nvarchar(255),
    @BulkPaid bit,
    @PaymentType nvarchar(255),
    @PaymentDate datetime

Select @InvoiceNo = InvoiceNo,
   @CustomerName = CustomerName,
   @PaymentAmount = PaymentAmount,
   @PaymentRefNumber = PaymentRefNumber,
   @BulkPaid = BulkPaid,
   @PaymentType = PaymentType
from inserted

Set @PaymentDate = GETDATE()

Insert into Payment_Log 
values (@InvoiceNo, @CustomerName, @PaymentAmount, @PaymentRefNumber, @BulkPaid, @PaymentType, @PaymentDate)

Below is a screenshot of SQL Server Management Studio that shows the rows being inserted into the middle of the table data. Thanks in advance for the help guys.

enter image description here

  • 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-09T17:03:39+00:00Added an answer on June 9, 2026 at 5:03 pm

    Datasets don’t have an order. This means that SELECT * FROM x can return the results in a different order every time.

    The only time that data is guaranteed to come back in the same order is when you specify an ORDER BY clause.

    That said, there are circumstances that make the data normally come back in a certain order. The most visible one is with a clustered index.

    This makes me wonder if the two tables have a Primary Key or not. Check all the indexes on each table and, at the very least, enforce a Primary Key.

    As an aside, triggers in SQL Server are not fired for each row, but each batch. This can mean that the inserted table can contain more than just one row. (For example, when bulk inserting test data, or re-loading a large batch of transactions.)

    For this reason, copying the data into variable is not a standard practice. Instead, you could just do the following…

    ALTER trigger [dbo].[PaymentHistory] on [dbo].[Payments]
    for insert as
    
    INSERT INTO
      Payment_Log
    SELECT
      InvoiceNo, CustomerName, PaymentAmount, PaymentRefNumber,
      BulkPaid,  PaymentType,  GetDate()
    FROM
      inserted
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently started work at a new company and a .net web application we
I recently inherited a Silverlight web project that uses WCF services to handle asynchronous
I recently inherited a Ubuntu Hardy box that acts rather funky out-of-the-box. The first
I recently inherited an e-commerce app (Java/Struts) that I'm porting to Rails. The thing
I've recently inherited a web project from a workmate who left to join another
I've recently inherited a .Net Web App with a 4 layer setup. As per
I have recently inherited a MOSS 2007 based application primarily involving an InfoPath 2007
I've recently inherited a database driven e-commerce site written in C# ASP.Net, with an
My application I've recently inherited is FULL of deprecation warnings about the constructor: Date
I just recently inherited a Rails application and am debating an architectural decision moving

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.