خرید بک لینک

Vote count: 0

I have two tables "EnrolledSubjects" and "StudentAccounts" in SqlServer. Obviously the enrolled subjects should go to the former while their fees should go to the latter. I use the simple Insert Statement for both tables but the problem is, how can I be sure that when one of the tables fail on insert, the other table must not insert anything too. I can use try-catch like so:

try
{
  insert statement to EnrolledSubjects table;
  insert statement to StudentAccounts table;
} catch(Exception ex) {
  get the error here
}

but what if there is no error in inserting to the EnrolledSubjects but error occurs in the insertion to the StudentAccounts? Then that means I would need to delete whatever was inserted to the EnrolledSubjects table.
Can you please tell me how to implement this right according to my specification. Thk you.

asked 34 secs ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 15 تير 1395 ساعت: 11:44

صفحه بندی