where ×Ӿ䲻½ö½öÖ§³Ö "where ÁÐÃû = Öµ" ÕâÖÖÃûµÈÓÚÖµµÄ²éѯÐÎʽ, ¶ÔÒ»°ãµÄ±È½ÏÔËËãµÄÔËËã·û¶¼ÊÇÖ§³ÖµÄ, ÀýÈç =¡¢>¡¢<¡¢>=¡¢<¡¢!= ÒÔ¼°Ò»Ð©À©Õ¹ÔËËã·û is [not] null¡¢in¡¢like µÈµÈ¡£ »¹¿ÉÒÔ¶Ô²éѯÌõ¼þʹÓà or ºÍ and ½øÐÐ×éºÏ²éѯ, ÒÔºó»¹»áѧµ½¸ü¼Ó¸ß¼¶µÄÌõ¼þ²éѯ·½Ê½, ÕâÀï²»ÔÙ¶à×ö½éÉÜ¡£
ʾÀý:
²éѯÄêÁäÔÚ21ËêÒÔÉϵÄËùÓÐÈËÐÅÏ¢: select * from students where age > 21;
²éѯÃû×ÖÖдøÓÐ "Íõ" ×ÖµÄËùÓÐÈËÐÅÏ¢: select * from students where name like "%Íõ%";
²éѯidСÓÚ5ÇÒÄêÁä´óÓÚ20µÄËùÓÐÈËÐÅÏ¢: select * from students where id<5 and age>20;
5.2.2¡¢¾ÛºÏº¯Êý5.3¡¢É¾³ýÊý¾Ý
delete from ±íÃû [ɾ³ýÌõ¼þ];
ɾ³ý±íÖÐËùÓÐÊý¾Ý£ºdelete from students;
ɾ³ýidΪ10µÄÐÐ: delete from students where id=10;
ɾ³ýËùÓÐÄêÁäСÓÚ88ËêµÄÊý¾Ý: delete from students where age<88;
5.4¡¢¸üÐÂÊý¾Ýupdate Óï¾ä¿ÉÓÃÀ´Ð޸ıíÖеÄÊý¾Ý, »ù±¾µÄʹÓÃÐÎʽΪ:
update ±íÃû³Æ set ÁÐÃû³Æ=ÐÂÖµ where ¸üÐÂÌõ¼þ;
Update ±íÃû set ×Ö¶Î=Öµ ÁÐ±í ¸üÐÂÌõ¼þ
ʹÓÃʾÀý:
½«idΪ5µÄÊÖ»úºÅ¸ÄΪĬÈϵÄ"-": update students set tel=default where id=5;
½«ËùÓÐÈ˵ÄÄêÁäÔö¼Ó1: update students set age=age+1;
½«ÊÖ»úºÅΪ 13723887766 µÄÐÕÃû¸ÄΪ "ÕŹû", ÄêÁä¸ÄΪ 19: update students set, age=19 where tel="13723887766";
5.5¡¢Ð޸ıíalter table Óï¾äÓÃÓÚ´´½¨ºó¶Ô±íµÄÐÞ¸Ä, »ù´¡Ó÷¨ÈçÏÂ:
5.5.1¡¢Ìí¼ÓÁлù±¾ÐÎʽ: alter table ±íÃû add ÁÐÃû ÁÐÊý¾ÝÀàÐÍ [after ²åÈëλÖÃ];
ʾÀý:
ÔÚ±íµÄ×îºó×·¼ÓÁÐ address: alter table students add address char(60);
ÔÚÃûΪ age µÄÁкó²åÈëÁÐ birthday: alter table students add birthday date after age;
5.5.2¡¢ÐÞ¸ÄÁлù±¾ÐÎʽ: alter table ±íÃû change ÁÐÃû³Æ ÁÐÐÂÃû³Æ ÐÂÊý¾ÝÀàÐÍ;
ʾÀý:
½«±í tel ÁиÄÃûΪ phone: alter table students change tel phone char(12) default "-";
½« name ÁеÄÊý¾ÝÀàÐ͸ÄΪ char(9): alter table students change name name char(9) not null;
5.5.3¡¢É¾³ýÁлù±¾ÐÎʽ: alter table ±íÃû drop ÁÐÃû³Æ;
ʾÀý:
ɾ³ý age ÁÐ: alter table students drop age;
5.5.4¡¢ÖØÃüÃû±í»ù±¾ÐÎʽ: alter table ±íÃû rename бíÃû;
ʾÀý:
ÖØÃüÃû students ±íΪtemp: alter table students rename temp;
5.5.5¡¢É¾³ý±í»ù±¾ÐÎʽ: drop table ±íÃû;
ʾÀý: ɾ³ýstudents±í: drop table students;
5.5.6¡¢É¾³ýÊý¾Ý¿â»ù±¾ÐÎʽ: drop database Êý¾Ý¿âÃû;
ʾÀý: ɾ³ýlcoaÊý¾Ý¿â: drop database lcoa;
5.5.7¡¢Ò»Ç§ÐÐMySQL±Ê¼Ç
¡¡