title: (Sql Server) BEGIN TRANSACTION vs (Qt) QSqlDatabase.database().transaction()
body: <p>What is the difference in performance &amp; reliance when using Sql Server's BEGIN TRANSACTION vs Qt's QSqlDatabase.database().transaction(), does both do the same thing? Which is prefered?</p>
  
  <p>Example using Sql Server's Transaction: </p>
  
  <pre><code>_databaseConnection.connect()
  q = QtSql.QSqlQuery()
  q.prepare("""BEGIN TRANSACTION [Tran1]
                  BEGIN TRY
                      INSERT INTO Entity(Name, UserName)
                      SELECT :Name AS Name, :UserName AS UserName;
                      DECLARE @lastInsertedID INT
                      SET @lastInsertedID =  SCOPE_IDENTITY();
  
                      INSERT INTO MyEntity(Pk_MyEntityID)
                      SELECT @lastInsertedID;
  
                      SELECT @lastInsertedID;        --the result-set will return the last Inserted Id
  
                      COMMIT TRANSACTION [Tran1]
                  END TRY
  
                  BEGIN CATCH
                      ROLLBACK TRANSACTION [Tran1]
                  END CATCH""")
  q.bindValue(":Name", "MyName")
  q.bindValue(":UserName", "MyUsername")
  q.exec_()
  print("Inserted using Sql Server Transaction")
  </code></pre>
  
  <p>Example using Qt's Transaction:</p>
  
  <pre><code>_databaseConnection.connect()
  q = QtSql.QSqlQuery()
  QtSql.QSqlDatabase.database().transaction()
  q.prepare("""INSERT INTO Entity(Name, UserName)
                  SELECT :Name AS Name, :Username AS UserName;
                  DECLARE @lastInsertedID INT
                  SET @lastInsertedID =  SCOPE_IDENTITY();
  
              INSERT INTO MyEntity(Pk_MyEntityID)
                  SELECT @lastInsertedID;
  
              SELECT @lastInsertedID;    --the result-set will return the last Inserted Id""")
  q.bindValue(":Name", "MyName")
  q.bindValue(":Username", "MyUsername")
  q.exec_()
  QtSql.QSqlDatabase.database().commit()
  print("Inserted using Qt Transaction")
  </code></pre>