mysqlÖÐɾ³ý±í¼Í¼µÄÓï¾ä
mysql ÖÐɾ³ý±í¼Í¼µÄÓï¾äΪ delete£¬Ó﷨Ϊ delete from table_name where condition£¬ÓÃÓÚÖ¸¶¨É¾³ýÌõ¼þ¡£Ê¹Óà delete Óï¾äʱÐèÉóÉ÷£¬ÓÉÓÚËü»áÓÀÊÀɾ³ý¼Í¼¡£±ðµÄ£¬ÉÐÓÐÆäËûÓï·¨±äÌ壬°üÀ¨Ê¹Óà limit ÏÞÖÆɾ³ý¼Í¼Êý¡¢Ê¹Óà order by ÅÅÐòɾ³ý¼Í¼ºÍʹÓà truncate ¿ìËÙɾ³ýËùÓмͼ¡£
MySQL ɾ³ý±í¼Í¼µÄÓï¾ä
MySQL ÖÐɾ³ý±í¼Í¼µÄÓï¾äΪ DELETE¡£ËüµÄ»ù±¾Óï·¨ÈçÏ£º
DELETE FROM table_name WHERE condition;
µÇ¼ºó¸´ÖÆ
ÆäÖУº
table_name ÊÇҪɾ³ý¼Í¼µÄ±íÃû¡£
condition ÊÇÓÃÓÚÖ¸¶¨ÒªÉ¾³ýÄÄЩ¼Í¼µÄ¿ÉÑ¡Ìõ¼þ¡£
ʹÓÃʾÀý
ÀýÈ磬Ҫ´Ó users ±íÖÐɾ³ýËùÓоßÓÐ user_type = ‘guest’ µÄ¼Í¼£¬¿ÉÒÔʹÓÃÒÔÏÂÓï¾ä£º
DELETE FROM users WHERE user_type = 'guest';
µÇ¼ºó¸´ÖÆ
×¢ÖØÊÂÏî
DELETE Óï¾ä»áÓÀÊÀɾ³ý¼Í¼£¬Òò´ËÔÚʹÓÃʱÇëÎñ±ØСÐÄ¡£
ÈôÊÇδָ¶¨ WHERE ×Ӿ䣬Ôò½«É¾³ý±íÖеÄËùÓмͼ¡£
DELETE Óï¾ä²»»á×Ô¶¯Ìá½»¸ü¸Ä¡£ÐèҪʹÓà COMMIT »ò ROLLBACK ÊÖ¶¯Ìá½»»ò»Ø¹ö¸ü¸Ä¡£
ÆäËûÓï·¨±äÌå
³ýÁË»ù±¾Óï·¨Ö®Í⣬DELETE Óï¾äÉÐÓÐÆäËûÓï·¨±äÌ壬°üÀ¨£º
ʹÓà LIMIT ÏÞÖÆɾ³ýµÄ¼Í¼Êý£º
DELETE FROM table_name WHERE condition LIMIT number_of_rows;
µÇ¼ºó¸´ÖÆ
ʹÓà ORDER BY ¶ÔҪɾ³ýµÄ¼Í¼¾ÙÐÐÅÅÐò£º
DELETE FROM table_name WHERE condition ORDER BY column_name DESC LIMIT number_of_rows;
µÇ¼ºó¸´ÖÆ
ʹÓà TRUNCATE ¿ìËÙɾ³ýËùÓмͼ£º
TRUNCATE TABLE table_name;
µÇ¼ºó¸´ÖÆ
TRUNCATE ±È DELETE ¸ü¸ßЧ£¬ÓÉÓÚËü²»»áÖ´ÐÐÖðÐÐɾ³ý²Ù×÷¡£¿ÉÊÇ£¬ËüÎÞ·¨»Ö¸´ÒÑɾ³ýµÄ¼Í¼¡£
ÒÔÉϾÍÊÇmysqlÖÐɾ³ý±í¼Í¼µÄÓï¾äµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡