Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Databases Modifying Data with SQL Handling Errors When Manipulating Data Introduction to Transactions

Autocommitting:

What do you mean by some systems don't have autocommit turned on and thus we need to begin and commit after each statement. I remember you talked ABOUT IT IN the transactions section. The problem is I don't get why you would need to begin if you did not have to turn off autocommit cause it doesn't exist.

2 Answers

In PostgreSQL, all statements are automatically executed as transactions. You only need to use BEGIN and COMMIT when explicitly defining transaction blocks in a script.

In MySQL, every statement is written to disk sequentially because autocommit is turned on by default. You must implicitly turn off autocommit by wrapping your statements with START TRANSACTION and COMMIT.

It's also worth mentioning that MySQL only has 1 storage engine that supports transactions, InnoDB, which is now the default engine (used to be MyISAM prior to version 5.5).

Steven Parker
Steven Parker
218,830 Points

It looks like you already asked this same question twice before, here and here.

But not all databases have an autocommit feature that you can turn on and off. This information only applies to those which do. And if it is turned off, any changes you make will not be permanent until you give the commit command.