sqlÖÐÐ޸ıí½á¹¹µÄÓï¾ä
¿ÉÒÔͨ¹ý alter table Óï¾äÐ޸ıí½á¹¹£¬Ïêϸ²Ù×÷ÓУºÌí¼ÓÁУºalter table table_name add column_name data_type;ɾ³ýÁУºalter table table_name drop column column_name;ÐÞ¸ÄÁУºalter table table_name alter column column_name new_data_type;Ìí¼ÓÔ¼Êø£ºalter table table_name add constraint constr
Ð޸ıí½á¹¹µÄ SQL Óï¾ä
ÔÚ SQL ÖУ¬¿ÉÒÔͨ¹ý ALTER TABLE Óï¾äÀ´Ð޸ıí½á¹¹¡£´ËÓï¾ä¿ÉÒÔÓÃÀ´Ìí¼Ó¡¢É¾³ý»òÐ޸ıíµÄÁС¢Ô¼Êø»òË÷Òý¡£
Ìí¼ÓÁÐ
ALTER TABLE table_name ADD column_name data_type;
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
ALTER TABLE customers ADD phone_number VARCHAR(10);
µÇ¼ºó¸´ÖÆ
ɾ³ýÁÐ
ALTER TABLE table_name DROP COLUMN column_name;
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
ALTER TABLE customers DROP COLUMN age;
µÇ¼ºó¸´ÖÆ
ÐÞ¸ÄÁÐ
ALTER TABLE table_name ALTER COLUMN column_name NEW_DATA_TYPE;
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
ALTER TABLE customers ALTER COLUMN name VARCHAR(50);
µÇ¼ºó¸´ÖÆ
Ìí¼ÓÔ¼Êø
ALTER TABLE table_name ADD CONSTRAINT constraint_name [CONSTRAINT_TYPE];
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
ALTER TABLE orders ADD CONSTRAINT FK_customer FOREIGN KEY (customer_id) REFERENCES customers (customer_id);
µÇ¼ºó¸´ÖÆ
ɾ³ýÔ¼Êø
ALTER TABLE table_name DROP CONSTRAINT constraint_name;
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
ALTER TABLE orders DROP CONSTRAINT FK_customer;
µÇ¼ºó¸´ÖÆ
Ìí¼ÓË÷Òý
ALTER TABLE table_name ADD INDEX index_name (column_name);
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
ALTER TABLE customers ADD INDEX idx_name (name);
µÇ¼ºó¸´ÖÆ
ɾ³ýË÷Òý
ALTER TABLE table_name DROP INDEX index_name;
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
ALTER TABLE customers DROP INDEX idx_name;
µÇ¼ºó¸´ÖÆ
ͨ¹ýʹÓÃÕâЩ ALTER TABLE Óï¾ä£¬¿ÉÒÔÇáËÉÐ޸ıí½á¹¹£¬ÒÔ˳Ӧһֱת±äµÄÊý¾ÝÐèÇó¡£
ÒÔÉϾÍÊÇsqlÖÐÐ޸ıí½á¹¹µÄÓï¾äµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡