SQL ALTER TABLEµÄÓ÷¨
ÔÚ±í¸ñ±»½¨Á¢ÔÚ×ÊÁÏ¿âÖкó£¬ÎÒÃdz£³£»á·¢ÏÖ£¬Õâ¸ö±í¸ñµÄ½á¹¹ÐèÒªÓÐËù¸Ä±ä¡£³£¼ûµÄ¸Ä±äÈçÏ£º
¼ÓÒ»¸öÀ¸Î»
ɾȥһ¸öÀ¸Î»
¸Ä±äÀ¸Î»Ãû³Æ
¸Ä±äÀ¸Î»µÄ×ÊÁÏÖÖÀà
ÒÔÉÏÁгöµÄ¸Ä±ä²¢²»ÊÇËùÓпÉÄܵĸı䡣ALTER TABLE Ò²¿ÉÒÔ±»ÓÃÀ´×÷ÆäËûµÄ¸Ä±ä£¬ÀýÈç¸Ä±äÖ÷¼ü¶¨Òå¡£
ALTER TABLE µÄÓï·¨ÈçÏ£º
ALTER TABLE "table_name"
[¸Ä±ä·½Ê½]
[¸Ä±ä·½Ê½] µÄÏêϸд·¨»áÒÀÎÒÃÇÏëÒª´ïµ½µÄÄ¿±ê¶øÓÐËù²»Í¬¡£ÔÙÒÔÉÏÁгöµÄ¸Ä±äÖУ¬[¸Ä±ä·½Ê½] ÈçÏ£º
¼ÓÒ»¸öÀ¸Î»: ADD "À¸Î» 1" "À¸Î» 1 ×ÊÁÏÖÖÀà"
ɾȥһ¸öÀ¸Î»: DROP "À¸Î» 1"
¸Ä±äÀ¸Î»Ãû³Æ: CHANGE "Ô±¾À¸Î»Ãû" "ÐÂÀ¸Î»Ãû" "ÐÂÀ¸Î»Ãû×ÊÁÏÖÖÀà"
¸Ä±äÀ¸Î»µÄ×ÊÁÏÖÖÀà: MODIFY "À¸Î» 1" "ÐÂ×ÊÁÏÖÖÀà"
ÒÔÏÂÎÒÃÇÓÃÔÚCREATE TABLE Ò»Ò³½¨³öµÄ customer ±í¸ñÀ´µ±×÷Àý×Ó£º
customer ±í¸ñ
À¸Î»Ãû³Æ
×ÊÁÏÖÖÀà
First_Name
char(50)
Last_Name
char(50)
Address
char(50)
City
char(50)
Country
char(25)
Birth_Date
date
µÚÒ»£¬ÎÒÃÇÒª¼ÓÈëÒ»¸ö½Ð×ö "gender" µÄÀ¸Î»¡£Õâ¿ÉÒÔÓÃÒÔϵÄÖ¸Áî´ï³É£º
ALTER table customer add Gender char(1)
Õâ¸öÖ¸ÁîÖ´ÐкóµÄ±í¸ñ¼Ü¹¹ÊÇ£º
customer ±í¸ñ
À¸Î»Ãû³Æ
×ÊÁÏÖÖÀà
First_Name
char(50)
Last_Name
char(50)
Address
char(50)
City
char(50)
Country
char(25)
Birth_Date
date
Gender
char(1)
½ÓÏÂÀ´£¬ÎÒÃÇÒª°Ñ "Address" À¸Î»¸ÄÃûΪ "Addr"¡£Õâ¿ÉÒÔÓÃÒÔϵÄÖ¸Áî´ï³É£º
ALTER table customer change Address Addr char(50)
Õâ¸öÖ¸ÁîÖ´ÐкóµÄ±í¸ñ¼Ü¹¹ÊÇ£º
customer ±í¸ñ
À¸Î»Ãû³Æ
×ÊÁÏÖÖÀà
First_Name
char(50)
Last_Name
char(50)
Addr
char(50)
City
char(50)
Country
char(25)
Birth_Date
date
Gender
char(1)
ÔÙÀ´£¬ÎÒÃÇÒª½« "Addr" À¸Î»µÄ×ÊÁÏÖÖÀà¸ÄΪ char(30)¡£Õâ¿ÉÒÔÓÃÒÔϵÄÖ¸Áî´ï³É£º
ALTER table customer modify Addr char(30)
Õâ¸öÖ¸ÁîÖ´ÐкóµÄ±í¸ñ¼Ü¹¹ÊÇ£º
customer ±í¸ñ
À¸Î»Ãû³Æ
×ÊÁÏÖÖÀà
First_Name
char(50)
Last_Name
char(50)
Addr
char(30)
City
char(50)
Country
char(25)
Birth_Date
date
Gender
char(1)
×îºó£¬ÎÒÃÇҪɾ³ý "Gender" À¸Î»¡£Õâ¿ÉÒÔÓÃÒÔϵÄÖ¸Áî´ï³É£º
ALTER table customer drop Gender
Õâ¸öÖ¸ÁîÖ´ÐкóµÄ±í¸ñ¼Ü¹¹ÊÇ£º
customer ±í¸ñ
À¸Î»Ãû³Æ
×ÊÁÏÖÖÀà
First_Name
char(50)
Last_Name
char(50)
Addr
char(30)
City
char(50)
Ïà¹ØÎĵµ£º
µ½Ä¿Ç°ÎªÖ¹£¬ÎÒÃÇÒÑѧµ½ÈçºÎ½åÓÉ SELECT ¼° WHEREÕâÁ½¸öÖ¸Á×ÊÁÏÓɱí¸ñÖÐ×¥³ö¡£²»¹ýÎÒÃÇÉÐδÌáµ½ÕâЩ×ÊÁÏÒªÈçºÎÅÅÁС£ÕâÆäʵÊÇÒ»¸öºÜÖØÒªµÄÎÊÌâ¡£ÊÂʵÉÏ£¬ÎÒÃǾ³£ÐèÒªÄܹ»½«×¥³öµÄ×ÊÁÏ×öÒ»¸öÓÐϵͳµÄÏÔʾ¡£Õâ¿ÉÄÜÊÇÓÉСÍù´ó (ascending) »òÊÇÓÉ´óÍùС(descending)¡£ÔÚÕâÖÖÇé¿öÏ£¬ÎÒÃǾͿÉÒÔÔËÓà ORDER BYÕâ¸öÖ¸ÁîÀ´´ïµ½ ......
ÎÒÃÇÏÖÔڻص½º¯ÊýÉÏ¡£¼ÇµÃÎÒÃÇÓà SUM Õâ¸öÖ¸ÁîÀ´Ëã³öËùÓÐµÄ Sales (ÓªÒµ¶î)°É£¡Èç¹ûÎÒÃǵÄÐèÇó±ä³ÉÊÇÒªËã³öÿһ¼äµê (store_name) µÄÓªÒµ¶î (sales)£¬ÄÇÔõô°ìÄØ£¿ÔÚÕâ¸öÇé¿öÏ£¬ÎÒÃÇÒª×öµ½Á½¼þÊ£ºµÚÒ»£¬ÎÒÃǶÔÓÚ store_name ¼° Sales ÕâÁ½¸öÀ¸Î»¶¼ÒªÑ¡³ö¡£µÚ¶þ£¬ÎÒÃÇÐèҪȷÈÏËùÓÐµÄ sales ¶¼ÒªÒÀÕÕ¸÷¸ö store_name À´·Ö¿ª ......
֮ǰÎÒÃÇ¿´µ½µÄ×óÁ¬½Ó (left join)£¬ÓÖ³ÆÄÚ²¿Á¬½Ó (inner join)¡£ÔÚÕâ¸öÇé¿öÏ£¬ÒªÁ½¸ö±í¸ñÄÚ¶¼ÓÐͬÑùµÄÖµ£¬ÄÇÒ»±Ê×ÊÁϲŻᱻѡ³ö¡£ÄÇÈç¹ûÎÒÃÇÏëÒªÁгöÒ»¸ö±í¸ñÖÐÿһ±ÊµÄ×ÊÁÏ£¬ÎÞÂÛËüµÄÖµÔÚÁíÒ»¸ö±í¸ñÖÐÓÐûÓгöÏÖ£¬ÄǸÃÔõô°ìÄØ£¿ÔÚÕâ¸öʱºò£¬ÎÒÃǾÍÐèÒªÓõ½ SQL OUTER JOIN (ÍⲿÁ¬½Ó) µÄÖ¸Áî¡£
ÍⲿÁ¬½ÓµÄÓï·¨ÊÇÒÀÊý¾ ......
±í¸ñÊÇÊý¾Ý¿âÖд¢´æ×ÊÁϵĻù±¾¼Ü¹¹¡£ÔÚ¾ø´ó²¿·ÝµÄÇé¿öÏ£¬Êý¾Ý¿â³§É̲»¿ÉÄÜÖªµÀÄúÐèÒªÈçºÎ´¢´æÄúµÄ×ÊÁÏ£¬ËùÒÔͨ³£Äú»áÐèÒª×Ô¼ºÔÚÊý¾Ý¿âÖн¨Á¢±í¸ñ¡£ËäÈ»Ðí¶àÊý¾Ý¿â¹¤¾ß¿ÉÒÔÈÃÄúÔÚ²»ÐèÓõ½ SQL µÄÇé¿öϽ¨Á¢±í¸ñ£¬²»¹ýÓÉÓÚ±í¸ñÊÇÒ»¸ö×î»ù±¾µÄ¼Ü¹¹£¬ÎÒÃǾö¶¨°üÀ¨ CREATE TABLE µÄÓï·¨ÔÚÕâ¸öÍøÕ¾ÖС£
ÔÚÎÒÃÇÌøÈë CREATE TABL ......