sqlÖÐÐ޸ıíµÄÏÂÁî
sql ÖÐÐ޸ıíµÄÏÂÁîÓУºalter table£ºÖ´ÐÐÖÖÖÖÐ޸ıí²Ù×÷¡£add column£ºÌí¼ÓÐÂÁС£drop column£ºÉ¾³ýÁС£modify column£ºÐÞ¸ÄÁеÄÀàÐÍ¡¢Ô¼Êø»òĬÈÏÖµ¡£rename column£ºÖØÃüÃûÁС£add primary key£ºÌí¼ÓÖ÷¼üÔ¼Êø¡£add foreign key£ºÌí¼ÓÍâ¼üÔ¼Êø¡£alter table rename to£ºÖØÃüÃû±í¡£
SQL ÖÐÐ޸ıíµÄÏÂÁî
Ð޸ıíµÄÏÂÁîÊÇ SQL ÖÐÓÃÓÚ¸ü¸Ä±í½á¹¹µÄÏÂÁî¡£ÕâЩÏÂÁîÔÊÐíÄúÌí¼Ó¡¢É¾³ý»òÐ޸ıíÖеÄÁУ¬¸ü¸ÄÔ¼Êø£¬»òÖØÃüÃû±í¡£
Ö÷ÒªÏÂÁî
×î³£ÓõÄÐ޸ıíÏÂÁî°üÀ¨£º
ALTER TABLE£ºÓÃÓÚÖ´ÐÐÖÖÖÖÐ޸ıí²Ù×÷¡£
ADD COLUMN£ºÌí¼ÓÐÂÁС£
DROP COLUMN£ºÉ¾³ýÁС£
MODIFY COLUMN£ºÐÞ¸ÄÁеÄÀàÐÍ¡¢Ô¼Êø»òĬÈÏÖµ¡£
RENAME COLUMN£ºÖØÃüÃûÁС£
ADD PRIMARY KEY£ºÌí¼ÓÖ÷¼üÔ¼Êø¡£
ADD FOREIGN KEY£ºÌí¼ÓÍâ¼üÔ¼Êø¡£
ALTER TABLE RENAME TO£ºÖØÃüÃû±í¡£
ʹÓÃÒªÁì
Ð޸ıíÏÂÁîµÄ»ù±¾Ó﷨Ϊ£º
ALTER TABLE [±íÃû] [Ð޸IJÙ×÷];
µÇ¼ºó¸´ÖÆ
ÀýÈ磬ҪÌí¼ÓÒ»¸öÐÂÁÐ age µ½ users ±í£¬¿ÉÒÔÖ´ÐÐÒÔÏÂÏÂÁ
ALTER TABLE users ADD COLUMN age INT;
µÇ¼ºó¸´ÖÆ
Ҫɾ³ýÁÐ address£¬¿ÉÒÔÖ´ÐУº
ALTER TABLE users DROP COLUMN address;
µÇ¼ºó¸´ÖÆ
×¢ÖØÊÂÏî
Ô¼Êø²»¿ÉÎ¥·´£ºÐ޸ıíʱ£¬Äú²»¿ÉÎ¥·´ÏÖÓÐÔ¼Êø¡£ÀýÈ磬Äú²»¿Éɾ³ýÒýÓÃÏÖÓÐÍâ¼üÔ¼ÊøµÄÁС£
±¸·ÝÊý¾Ý£ºÔÚÖ´ÐÐÖØ´óÐ޸ıí²Ù×÷֮ǰ£¬Ê¼ÖÕ±¸·Ý±íÊý¾Ý¡£
Ëø±í£ºÔÚÖ´ÐÐijЩÐ޸ıí²Ù×÷ʱ£¬Êý¾Ý¿â¿ÉÄÜ»áËøס±í£¬×èÖ¹ÆäËûÓû§»á¼û¡£
ʹÓà WITH CHECK OPTION£ºÔÚÐ޸ıíÔ¼Êøʱ£¬Äú¿ÉÒÔʹÓà WITH CHECK OPTION À´Ç¿ÖÆÊý¾Ý¿â¼ì²éÏÖÓÐÊý¾ÝÊÇ·ñÖª×ãÐÂÔ¼Êø¡£
ÒÔÉϾÍÊÇsqlÖÐÐ޸ıíµÄÏÂÁîµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡