MySQL在指定列之前或之后插入列

To add a column called email to the contacts table created in Create a basic MySQL table with a datatype of VARCHAR(80), use the following SQL statement:

[sql] view plain copy
 
print ?
  1. ALTER TABLE contacts ADD email VARCHAR(60);  
ALTER TABLE contacts ADD email VARCHAR(60);

This first statement will add the email column to the end of the table. To insert the new column after a specific column, such as name, use this statement:

[sql] view plain copy
 
print ?
  1. ALTER TABLE contacts ADD email VARCHAR(60) AFTER name;  
ALTER TABLE contacts ADD email VARCHAR(60) AFTER name;



If you want the new column to be first, use this statement:

[sql] view plain copy
 
print ?
  1. ALTER TABLE contacts ADD email VARCHAR(60) FIRST;  
ALTER TABLE contacts ADD email VARCHAR(60) FIRST;

猜你喜欢

转载自weitao1026.iteye.com/blog/2343566