0

If I execute two stored procedures in the same connection like:

exec dbo.SP1;
exec dbo.SP2;

Can I be sure that SP2 not will start before SP1 is finished?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
xhr489
  • 1,957
  • 13
  • 39
  • 7
    Yes - TSQL is sequential - no async here. – Dale K Oct 14 '20 at 08:26
  • 2
    SQL is a sequential language, a statement further in the batch will not be started till those earlier in the batch complete. – Thom A Oct 14 '20 at 08:26
  • @DaleK what if the first one fails. Yes thanks for the link – xhr489 Oct 14 '20 at 08:35
  • Define fail? If its a transaction breaking error it will not run SP 2, if its a minor error it will. If you care you should add error handling to control it. – Dale K Oct 14 '20 at 08:36
  • 2
    *"what if the first one fails. Yes thanks for the link"* Depends on the severity of the error, your `XACT_ABORT` settings, etc. – Thom A Oct 14 '20 at 08:39
  • @Larnu what if I want to start to SPs simultaneously on the same session? is that possible? – xhr489 Oct 14 '20 at 12:29
  • With 2 separate sessions, yes, @David . – Thom A Oct 14 '20 at 12:32

0 Answers0