MySQLË÷Òý·ÖÎöºÍÓÅ»¯£¨×ª£©
ʲôÊÇË÷Òý£¿
Ë÷
ÒýÓÃÀ´¿ìËÙµØÑ°ÕÒÄÇЩ¾ßÓÐÌض¨ÖµµÄ¼Ç¼£¬ËùÓÐMySQLË÷Òý¶¼ÒÔB-Ê÷µÄÐÎʽ±£´æ¡£Èç¹ûûÓÐË÷Òý£¬Ö´ÐвéѯʱMySQL±ØÐë´ÓµÚÒ»¸ö¼Ç¼¿ªÊ¼É¨ÃèÕû¸ö±íµÄ
ËùÓмǼ£¬Ö±ÖÁÕÒµ½·ûºÏÒªÇóµÄ¼Ç¼¡£±íÀïÃæµÄ¼Ç¼ÊýÁ¿Ô½¶à£¬Õâ¸ö²Ù×÷µÄ´ú¼Û¾ÍÔ½¸ß¡£Èç¹û×÷ΪËÑË÷Ìõ¼þµÄÁÐÉÏÒѾ´´½¨ÁËË÷Òý£¬MySQLÎÞÐèɨÃèÈκμǼ¼´
¿ÉѸËٵõ½Ä¿±ê¼Ç¼ËùÔÚµÄλÖá£Èç¹û±íÓÐ1000¸ö¼Ç¼£¬Í¨¹ýË÷Òý²éÕҼǼÖÁÉÙÒª±È˳ÐòɨÃè¼Ç¼¿ì100±¶,¸öÈ˸оõ¿ì100±¶Óеã¿äÕÅ¡£
¼ÙÉèÎÒÃÇ´´½¨ÁËÒ»¸öÃûΪpeopleµÄ±í£º
CODE:
CREATE TABLE people ( peopleid SMALLINT NOT NULL, name CHAR(50) NOT NULL );
ºó£¬ÎÒÃÇÍêÈ«Ëæ»ú°Ñ1000¸ö²»Í¬nameÖµ²åÈëµ½people±í¡£
¿ÉÒÔ¿´µ½£¬ÔÚÊý¾ÝÎļþÖÐnameÁÐûÓÐÈκÎÃ÷È·µÄ´ÎÐò¡£Èç¹ûÎÒÃÇ´´½¨ÁËnameÁеÄË÷Òý£¬MySQL½«ÔÚË÷ÒýÖÐÅÅÐònameÁУº
¶Ô
ÓÚË÷ÒýÖеÄÿһÏMySQLÔÚÄÚ²¿ÎªËü±£´æÒ»¸öÊý¾ÝÎļþÖÐʵ¼Ê¼Ç¼ËùÔÚλÖõēָÕ딡£Òò´Ë£¬Èç¹ûÎÒÃÇÒª²éÕÒnameµÈÓÚ“Mike”¼Ç¼µÄ
peopleid£¨SQLÃüÁîΪ“SELECT peopleid from people WHERE
name='Mike';”£©£¬MySQLÄܹ»ÔÚnameµÄË÷ÒýÖвéÕÒ“Mike”Öµ£¬È»ºóÖ±½Óתµ½Êý¾ÝÎļþÖÐÏàÓ¦µÄÐУ¬×¼È·µØ·µ»Ø¸ÃÐеÄ
peopleid£¨999£©¡£ÔÚÕâ¸ö¹ý³ÌÖУ¬MySQLÖ»Ðè´¦ÀíÒ»¸öÐоͿÉÒÔ·µ»Ø½á¹û¡£Èç¹ûûÓГname”ÁеÄË÷Òý£¬MySQLҪɨÃèÊý¾ÝÎļþÖеÄËùÓÐ
¼Ç¼£¬¼´1000¸ö¼Ç¼£¡ÏÔÈ»£¬ÐèÒªMySQL´¦ÀíµÄ¼Ç¼ÊýÁ¿Ô½ÉÙ£¬ÔòËüÍê³ÉÈÎÎñµÄËٶȾÍÔ½¿ì¡£
Ë÷ÒýµÄÀàÐÍ
MySQLÌṩ¶àÖÖË÷ÒýÀàÐ͹©Ñ¡Ôñ£º
ÆÕͨË÷Òý
ÕâÊÇ×î»ù±¾µÄË÷ÒýÀàÐÍ£¬¶øÇÒËüûÓÐΨһÐÔÖ®ÀàµÄÏÞÖÆ¡£ÆÕͨË÷Òý¿ÉÒÔͨ¹ýÒÔϼ¸ÖÖ·½Ê½´´½¨£º
CODE:
´´½¨Ë÷Òý£¬ÀýÈçCREATE INDEX <Ë÷ÒýµÄÃû×Ö>; ON tablename (ÁеÄÁбí);
ÐÞ¸Ä±í£¬ÀýÈçALTER TABLE tablename ADD INDEX [Ë÷ÒýµÄÃû×Ö] (ÁеÄÁбí);
´´½¨±íµÄʱºòÖ¸¶¨Ë÷Òý£¬ÀýÈçCREATE TABLE tablename ( [...], INDEX [Ë÷ÒýµÄÃû×Ö] (ÁеÄÁбí) );
ΨһÐÔË÷Òý
ÕâÖÖË÷ÒýºÍÇ°ÃæµÄ“ÆÕͨË÷Òý”»ù±¾Ïàͬ£¬µ«ÓÐÒ»¸öÇø±ð£ºË÷ÒýÁеÄËùÓÐÖµ¶¼Ö»ÄܳöÏÖÒ»´Î£¬¼´±ØÐëΨһ¡£Î¨Ò»ÐÔË÷Òý¿ÉÒÔÓÃÒÔϼ¸ÖÖ·½Ê½´´½¨£º
CODE:
´´½¨Ë÷Òý£¬ÀýÈçCREATE UNIQUE INDEX <Ë÷ÒýµÄÃû×Ö>; ON tablename (ÁеÄÁбí);
ÐÞ¸Ä±í£¬ÀýÈçALTER TABLE tablename ADD UNIQUE [Ë÷ÒýµÄÃû×Ö] (ÁеÄÁбí);
´´½¨±íµÄʱºòÖ¸¶¨Ë÷Òý£¬ÀýÈçCREATE TABLE tablename ( [...], UNIQUE [Ë÷
Ïà¹ØÎĵµ£º
²»Í¬Êý¾Ý¿âÖ®¼äµÄÓï·¨²îÒ컹Õæ²»ÉÙ~Òª±ÀÀ£ÁË¡£
1.´´½¨´ø×ÔÔöÁÐÁÙʱ±í£ºcreate TEMPORARY table t(id int AUTO_INCREMENT PRIMARY key, u_name varchar(50));--Ϊʲô±ØÐëÒªÖ÷¼ü£¿£¡
ÏòÕâ¸öÁÙʱ±íÖвåÈëÊý¾Ý£ºinsert into t values(null, 'zdy');--Ϊʲôһ¶¨Òª¼Ónull£¿£¡
2.°ÑÒ»ÕűíµÄ²éѯ½á¹û²åÈëÁÙʱ±í£ºinsert into t ......
1¡¢Íâ¼üµÄÒýÓÃÀàÐͲ»Ò»Ñù£¬Ö÷¼üÊÇintÍâ¼üÊÇchar
2¡¢ÕÒ²»µ½Ö÷±íÖÐ ÒýÓõÄÁÐ
3¡¢Ö÷¼üºÍÍâ¼üµÄ×Ö·û±àÂë²»Ò»ÖÂ
4.»¹ÓÐÒª½¨Á¢Íâ¼üµÄ»°£¬ÒªÏȽ¨Á¢Ë÷Òý¡£Ã»Óн¨Á¢Ë÷ÒýÒ²»á³ö´í¡£
ÎÒµÄÎÊÌâ½â¾ö·½°¸ÊÇÔÚsqlºóÃæ¼ÓÉÏÁËÈçϾ仰,ok!³É¹¦µ¼Èë½Å±¾
ENGINE=MyISAM DEFAULT CHARSET=utf8;
charset¶ÔÓ¦µÄ»»³ÉÄãµÄÖ÷¼ü±íµÄ×Ö·û¼¯ ......
ÔÚApache, PHP, MySQLµÄÌåϵ¼Ü¹¹ÖУ¬MySQL¶ÔÓÚÐÔÄܵÄÓ°Ïì×î´ó£¬Ò²ÊǹؼüµÄºËÐIJ¿·Ö¡£¶ÔÓÚDiscuz!ÂÛ̳³ÌÐòÒ²ÊÇÈç´Ë£¬MySQLµÄÉèÖÃÊÇ·ñºÏÀíÓÅ»¯£¬Ö±½ÓÓ°Ïìµ½ÂÛ̳µÄËٶȺͳÐÔØÁ¿£¡Í¬Ê±£¬MySQLÒ²ÊÇÓÅ»¯ÄѶÈ×î´óµÄÒ»¸ö²¿·Ö£¬²»µ«ÐèÒªÀí½âһЩMySQLרҵ֪ʶ£¬Í¬Ê±»¹ÐèÒª³¤Ê±¼äµÄ¹Û²ìͳ¼Æ²¢ÇÒ¸ù¾Ý¾Ñé½øÐÐÅжϣ¬È»ºóÉèÖúÏÀíµÄ²ÎÊý¡ ......
ͨ¹ýMySQLÄÚÖÃÈ«ÎļìË÷ʵÏÖÖÐÎĵÄÏà¹Ø¼ìË÷
¹Ø¼ü×Ö£ºMySQL È«ÎļìË÷ È«ÎÄË÷Òý ÖÐÎÄ·Ö´Ê ¶þÔª·Ö´Ê ÇøλÂë ÏàËƶÈ
×¢£º±¾ÎÄʹÓõÄMySQL°æ±¾Îª£ºMySQL 4.0.x
ÔÚMySQL4ÖУ¬ÊÇÒѾ¿ªÊ¼Ö§³ÖÈ«ÎļìË÷£¨Ë÷Òý£©µÄÁË¡£µ«ÊÇÖ»ÊǶÔÓ¢ÎÄÖ§³ÖÈ«ÎļìË÷¡£
ÓÉÓÚÓ¢ÎÄÔÚÊéдÉϵÄÌØÊâÐÔ£¬Ê¹µÃ·Ö´ÊËã·¨Ïà¶ÔÖÐÎÄÀ´Ëµ£¬¼òµ¥µÃ¶à¡£Ò»°ãÀ´Ëµ£¬ÎÒÃÇ ......
¸ã¶¨MySQLÊý¾Ý¿âÖÐÎÄÄ£ºý¼ìË÷ÎÊÌâ
×÷Õß: bianceng, ¡¡³ö´¦:ITר¼ÒÍøÂÛ̳,¡¡ÔðÈαà¼: ³Â×Óç÷,¡¡
2009-10-28 07:00
¡¡¡¡ÔÚ MySQLÏ£¬ÔÚ½øÐÐÖÐÎÄÄ£ºý¼ìË÷ʱ£¬¾³£»á·µ»ØһЩÓëÖ®²»Ïà¹ØµÄ¼Ç¼£¬Èç²éÕÒ "%a%" ʱ£¬·µ»ØµÄ¿ÉÄÜÓÐÖÐÎÄ×Ö·û£¬È´Ã»ÓÐa×Ö·û´æÔÚ¡£
¡¡¡¡ÔÚ MySQLÏ£¬ÔÚ½øÐÐÖÐÎÄÄ£ºý¼ìË÷ʱ£¬¾³£»á·µ»ØһЩÓë ......