The quiz and exercises are provided to help you solidify your understanding of the material covered today. Try to understand the quiz and exercise answers before continuing to tomorrow's lesson.
1: | True or False: A table lock, when obtained by one client, prevents other clients from reading from or writing to a table. |
A1: | True for a write lock. With a read lock, the statement is not true because it allows other threads to read from the table. |
2: | True or False: When preparing to run a query on several tables, any lock must be obtained on all those tables. |
A2: | True. You must obtain suitable locks on all tables that will be used by your queries, until you unlock the tables. |
3: | True or False: With transaction-safe processing, you must issue a BEGIN to declare the start of a transaction. |
A3: | True. However, you must use transaction-safe table types (InnoDB or BDB) or BEGIN will have no effect. |
4: | In transaction-safe processing, what SQL command saves data to disk? |
A4: | COMMIT. |
5: | In transaction-safe processing, what SQL command undoes all changes without writing to disk? |
A5: | ROLLBACK. |
1: | Imagine that you have a table called orders. You want to update it while no other threads can read from it. You also have a table called products, which you want to read from but not update. Write the syntax for the appropriate locking and unlocking of the tables. |
A1: | You should have this:
LOCK TABLES orders WRITE, products READ ... UNLOCK TABLES |
2: | What line must you have in your server's my.cnf file to make it use InnoDB? Assume that you want it to have a 50MB tablespace, auto-extending. |
A2: | In the [mysqld] section, you should have this:
[mysqld] ... innodb_data_file_path = ibdata1:50M:autoextend |
13.59.38.41