2011年5月9日 星期一

MySQL notes

Change a column name:
alter table tablename change oldname newname varchar (10) ;

Add a column to an existing table:
(1)
ALTER TABLE contacts ADD email VARCHAR(60); to the end of the table
(2) ALTER TABLE contacts ADD email VARCHAR(60) AFTER name; the new column after a specific column
(3) ALTER TABLE contacts ADD email VARCHAR(60) FIRST; the new column to be first
(4) INSERT INTO table1 (col1, col2, col3) SELECT col1, col2, col3 FROM table2 WHERE col4='some value'; Copying rows from one table to another
(5) INSERT INTO settings_b SELECT * FROM settings_a WHERE account = 'bishop'; Copying rows from one table to another

沒有留言:

張貼留言