MySQLÐÐËøÉîÈëÑо¿
×öÏîĿʱÓÉÓÚÒµÎñÂß¼µÄÐèÒª£¬±ØÐë¶ÔÊý¾Ý±íµÄÒ»Ðлò¶àÐмÓÈëÐÐËø£¬¾Ù¸ö×î¼òµ¥µÄÀý×Ó£¬Í¼Êé½èÔÄϵͳ¡£¼ÙÉè
id=1
µÄÕâ±¾Êé¿â´æΪ
1
£¬µ«ÊÇÓÐ
2
¸öÈËͬʱÀ´½èÕâ±¾Ê飬´Ë´¦µÄÂ߼Ϊ
Select restnum from book where id =1 ;
-- Èç¹û restnum ´óÓÚ 0 £¬Ö´ÐÐ update
Update book set restnum=restnum-1 where id=1 ;
ÎÊÌâ¾ÍÀ´ÁË£¬µ±
2
¸öÈËͬʱÀ´½èµÄʱºò£¬ÓпÉÄܵÚÒ»¸öÈËÖ´ÐÐ
select
Óï¾äµÄʱºò£¬µÚ¶þ¸öÈ˲åÁ˽øÀ´£¬ÔÚµÚÒ»¸öÈËûÀ´µÃ¼°¸üÐÂ
book
±íµÄʱºò£¬µÚ¶þ¸öÈ˲鵽Êý¾ÝÁË£¬ÆäʵÊÇÔàÊý¾Ý£¬ÒòΪµÚÒ»¸öÈË»á°Ñ
restnum
Öµ¼õ
1
£¬Òò´ËµÚ¶þ¸öÈ˱¾À´Ó¦¸ÃÊDz鵽
id=1
µÄÊé
restnum
Ϊ
0
ÁË£¬Òò´Ë²»»áÖ´ÐÐ
update
£¬¶ø»á¸æËßËü
id=1
µÄÊéûÓпâ´æ
ÁË£¬¿ÉÊÇÊý¾Ý¿âÄĶ®ÕâЩ£¬Êý¾Ý¿âÖ»¸ºÔðÖ´ÐÐÒ»ÌõÌõ
SQL
Óï¾ä£¬Ëü²Å²»¹ÜÖмäÓÐûÓÐÆäËû
sql
Óï¾ä²å½øÀ´£¬ËüÒ²²»ÖªµÀÒª°ÑÒ»¸ö
session
µÄ
sql
Óï¾äÖ´ÐÐÍêÔÙÖ´ÐÐÁíÒ»¸ö
session
µÄ¡£Òò´Ë»áµ¼Ö²¢·¢µÄʱºò
restnum
×îºóµÄ½á¹ûΪ
-1
£¬ÏÔÈ»ÕâÊDz»ºÏÀíµÄ£¬ËùÒÔ£¬²Å³öÏÖËøµÄ¸ÅÄ
Mysql
ʹÓÃ
innodb
ÒýÇæ¿ÉÒÔͨ¹ýË÷Òý
¶ÔÊý¾ÝÐмÓËø¡£ÒÔÉϽèÊéµÄÓï¾ä±äΪ£º
Begin;
Select restnum from book where id =1 for update ;
-- ¸ø id=1 µÄÐмÓÉÏÅÅËüËøÇÒ id ÓÐË÷Òý
Update book set restnum=restnum-1 where id=1 ;
Commit;
ÕâÑù£¬µÚ¶þ¸öÈËÖ´Ðе½
select
Óï¾äµÄʱºò¾Í»á´¦Óڵȴý״ֱ̬µ½µÚÒ»¸öÈËÖ´ÐÐ
commit
¡£´Ó¶ø±£Ö¤Á˵ڶþ¸öÈ˲»»á¶Áµ½µÚÒ»¸öÈËÐÞ¸ÄÇ°µÄÊý¾Ý¡£
ÄÇÕâÑùÊDz»ÊÇÍòÎÞһʧÁËÄØ£¬´ð°¸ÊÇ·ñ¶¨µÄ¡£¿´ÏÂÃæµÄÀý×Ó¡£
¸úÎÒÒ»²½Ò»²½À´£¬ÏȽ¨Á¢±í
CREATE TABLE `book` (
`id` int(11) NOT NULL auto_increment,
`num` int(11) default NULL,
`name` varchar(0) default NULL,
PRIMARY KEY (`id`),
KEY `asd` (`num`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk
ÆäÖÐ
num
×ֶμÓÁËË÷Òý
È»ºó²åÈëÊý¾Ý£¬ÔËÐУ¬
insert into book(num) values(11),(11),(11),(11),(11);
insert into book(num) values(22),(22),(22),(22),(22);
È»ºó´ò¿ª
2
¸ö
mysql
¿ØÖÆ̨´°¿Ú£¬Æäʵ¾ÍÊǽ¨Á¢
2
¸ö
session
×ö²¢·¢²Ù×÷
********************************************************************
ÔÚµÚÒ»¸ö
session
ÀïÔËÐУº
Ïà¹ØÎĵµ£º
¼ÇÁËһЩÓà Windows µÄÃüÁîÐÐÀ´²Ù×÷ MySQL µÄÖ¸Áî¡£
ÕªÒª
Á¬½á MySQL
->mysql -u username -p
username ÊÇÄãµÄÕʺÅÃû³Æ¡£
Ô¶³ÌÁ¬½á
->mysql -h hostname -u username -p
hostname ÊÇ MySQL Ö÷»úµÄÃû³Æ¡£
ÏÔʾȫ²¿µÄÊý¾Ý¿â
SHOW DATABASES;
mysql ÊÇ MySQL ÓÃÀ´´¢´æÕʺźÍȨÏÞµÄÊý¾Ý¿â£¬²»ÄÜɾ³ý¡£
Ñ¡Ôñ ......
ÄÚ´æ±íʹÓùþϣɢÁÐË÷Òý°ÑÊý¾Ý±£´æÔÚÄÚ´æÖУ¬Òò´Ë¾ßÓм«¿ìµÄËٶȣ¬Êʺϻº´æÖÐСÐÍÊý¾Ý¿â£¬µ«ÊÇʹÓÃÉÏÊܵ½Ò»Ð©ÏÞÖÆ£¬ÒÔÏÂÊÇÀ¶²ÝʹÓõÄһЩ¸ÐÊÜ¡£
1¡¢heap¶ÔËùÓÐÓû§µÄÁ¬½ÓÊǿɼûµÄ£¬ÕâʹµÃËü·Ç³£ÊʺÏ×ö»º´æ¡£
2¡¢½öÊʺÏʹÓõij¡ºÏ¡£heap²»ÔÊÐíʹÓÃxxxTEXTºÍxxxBLOBÊý¾ÝÀàÐÍ£»Ö»ÔÊÐíʹÓÃ=ºÍ<=>²Ù×÷·ûÀ´ËÑË÷¼Ç¼£¨²» ......
¹ØÓÚ·ÖÒ³µÄÓÅ»¯¡£
ÎÒÃÇÖªµÀ£¬ÔÚMySQLÖзÖÒ³ºÜ¼òµ¥£¬Ö±½ÓLIMIT page_no,page_total ¾Í¿ÉÒÔÁË¡£
¿ÉÊǵ±¼Ç¼ÊýÂýÂýÔö´óʱ£¬Ëý¾Í²»ÄÇôºÃʹÁË¡£
ÕâÀïÎÒÃÇ´´½¨ÕªÒª±íÀ´¼Ç¼ҳÂëºÍÔ±íÖ®¼äµÄ¹ØÁª¡£
ÏÂÃæΪ²âÊÔÊý¾Ý¡£
Ô±í£º
CREATE TABLE `t_group` (
`id` int(11) NOT NULL auto_increment,
`money` decim ......
1 MySQLÖ§³Öenum,ºÍsetÀàÐÍ£¬SQL Server²»Ö§³Ö
¡¡¡¡2 MySQL²»Ö§³Önchar,nvarchar,ntextÀàÐÍ
¡¡¡¡3 MySQLµÄµÝÔöÓï¾äÊÇAUTO_INCREMENT£¬¶øMS SQLÊÇidentity(1,1)
¡¡¡¡4 MS SQLĬÈϵ½´¦±í´´½¨Óï¾äµÄĬÈÏÖµ±íʾÊÇ((0)),¶øÔÚMySQLÀïÃæÊDz»ÔÊÐí´øÁ½À¨ºÅµÄ
¡¡¡¡5 MySQLÐèҪΪ±íÖ¸¶¨´æ´¢ÀàÐÍ
¡¡¡¡6 MS SQLʶ±ð·ûÊÇ[],[type]±íÊ ......