You are here: Articles > Computers & Technology > sql

 See more articles about "sql "

Tutorial Addendum on SQL - Locks And Deadlocks



 31 December 18:00   

    



    



    

This affiliate describes:

    



        

  • What are the types and levels of locks?

        



  •     

  • How table akin locks plan in MySQL?

        



  •     

  • How row akin locks plan in MySQL?

        



  •     



    



    

All addendum in affiliate are based MySQL 5.0 server.

    



    

Types and Levels of Locks

    



    

There are two types of locks:

    



        

  • Read Lock - The bound data is aloof for apprehend by the accepted session.

        

    Other sessions can apprehend the bound data. But they can not address (update) the bound data.

        

    A apprehend lock is aswell alleged a aggregate lock.

        



  •     

  • Write Lock - The bound data is aloof for address by the accepted session.

        

    Other sessions can not apprehend and address the bound data. A address lock is aswell alleged

        

    an absolute lock.

        



  •     



    



    

There are three levels of locks:

    



        

  • Table Lock - The lock is set at the table level. All rows in the bound table

        

    are locked.

        



  •     

  • Row Lock - The lock is set at the row level. Some rows of a table are locked.

        

    But additional rows are not locked.

        



  •     

  • Column Lock - The lock is set at the cavalcade level. Some columns of a row are locked.

        

    But additional columns are not locked.

        



  •     



    



    



    

Table Akin Locks in MySQL

    



    

The LOCK TABLES account sets table akin locks on defined tables. It aswell unlocks all

    

previously locks:

    



    

LOCK TABLES tbl_name {READ | WRITE}, tbl_name {READ | WRITE}, ...;

    



    



    

The Alleviate TABLES account unlocks all ahead locks:

    



    

UNLOCK TABLES;

    



    



    

The afterward analysis shows that how a bound table in one affair affects

    

its acceptance in addition session:

    



    

Session 1: Affair 2:

    



    

 

    

c:>mysqlinmysql test

    

mysql> Alert >;

    

>DROP TABLE IF EXISTS User;

    

>CREATE TABLE User (ID INT

    

> PRIMARY KEY, Name CHAR(8));

    

>INSERT INTO User Ethics (2,

    

> bill );

    

>-- Analysis 1;

    

>LOCK TABLES User READ;

    

c:>mysqlinmysql test

    

mysql> Alert >;

    

>SELECT * FROM User;

    

+----+------+

    

| 2 | bill |

    

+----+------+

    

>INSERT INTO User Ethics (3,

    

> jack );

    

(waiting for the lock to release)

    

>UNLOCK TABLES;

    

(insert done)

    

>-- Analysis 2;

    

>LOCK TABLES User WRITE;

    

>SELECT * FROM User;

    

(waiting for the lock to release)

    

>UNLOCK TABLES;

    

(select done)

    

+----+------+

    

| 2 | bill |

    

| 3 | jack |

    

+----+------+

    



    



 


 locked, locks, table, tables, level, session, write, unlock, mysql, select, insert, types, levels, notes, , lock the, locked data, lock tables, level locks, table level, unlock tables, locked table, table level locks, lock tables user, release unlock tables, insert into user, session other sessions, level locks work, current session other, tbl name {read,

Share Tutorial Addendum on SQL - Locks And Deadlocks:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Tutorial Addendum on SQL - Locks And Deadlocks
We all understand that assorted locks in assorted sessions could couldcause deadlocks. Let s see if we can make a deadlock in MySQL amid two sessions: mysql Alert ;DROP TABLE IF EXISTS User;

Tutorial Addendum on SQL - Addition to MySQL
This affiliate describes:What s in MySQL?How to use the SQL applicant apparatus mysql.How to dump data into files.How to amount data from fil

Tutorial Addendum on SQL - Addition to MySQL
To assassinate the statements in hello.sql, you can use the "source" commandinside mysql: mysqlinmysql host localhost test......mysql antecedent hello.sqlQuery OK, 0 rows affli

Tutorial Addendum on SQL - Operations and Expressions
This affiliate describes:Expressions.Arithmetic operations.Predicate operations.Date and time operations.Operation examp

Tutorial Addendum on SQL - Operations and Expressions
Predicate OperationsPredicate operations are operations that can be evaluated to accord a action of true or false:1. "Comparison" Predicates: Compares

Tutorial Addendum on SQL - Operations and Expressions
Operation ExamplesExample 1 NumericOps.sql NumericOps.sql Absorb (c) 1999 by Dr. Yang SELECT 1 + 2 AS LINE_1;SELECT 2 / 3 AS LINE_2;

Tutorial Addendum on SQL - MySQL - Stored Procedures
This affiliate describes:What is a stored procedure?How to make a stored procedure.How to canyon data through parameters.

Tutorial Addendum on SQL - MySQL - Stored Procedures
Here is a simple analysis on stored action the MySQL applicant tool: mysql USE test; mysql DELIMITER / ;mysql Make Action Msg() BEGIN Baddest CURRENT_TIME() AS Time;br

Tutorial Addendum on SQL - MySQL - Stored Action Accent
This affiliate describes:Local variables in stored procedures.Execution breeze ascendancy statements.Cursor accompanying statements.br

Tutorial Addendum on SQL - MySQL - Stored Action Accent
Below is a sample cipher that uses a while bend to admit assorted rows into a table: ProcedureLoop.sql Absorb (c) 2004 by Dr. Yang DROP2 DATABASE IF EXISTS HyTest;CREATE DATABASE H