Frage

i'm new programmer

  1. all i know is has 2 way to sql transaction control . But i want to know is

    1.1 when should be use transaction in program and when should be use transaction in database. 1.2 which is better (now i think sql transaction in program is better. But my boss want to use sql transaction in database)

  2. From first question. when i insert data to master table and details table.

    Below is my boss's stored procedure

    SaveOrder( 
    @customerID int,
    @value decimal(18,2),
    @details varchar(max)
    )
    

And i must send data like ...

SaveOrder(@customerID = 1,@value = 2500,@details = '(1,'apple',2,50),(2,'orange',3,70),(3,'banana',4,120)')

I disagree. but he said "don't want to use sql transaction in program."

How do you think with this. And which is better.

War es hilfreich?

Lösung

You say you're a new programmer. So I strongly advise you to do what your boss says. Not because he's your boss and you're a newbie but because:

  1. "I'm not really sure what I'm talking about so I asked some random strangers on StackOverflow and they said ... " is not a strong argument.
  2. Putting business rules in the database (stored procedures) or in the application is a long-running religious war to which there is no definitive answer, regardless of what anybody says.

Now you're right to be concerned about passing multiple detail records in a string. That's lame. It ought to be an array of some description. However, the correct approach in this situation is to work with your boss to improve the stored procedure's interface.

Finally, the bottom line is this: when we're working in a team building software consistency is a great virtue - even if it means using a sub-optimal approach.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top