1.增加一个字段(一列) alter table table_name add column column_name type default value; type指该字段的类型,value指该字段的默认值 例如: 复制代码 代码如下: alter table mybook add column publish_house varchar(10) default ”;
2.更改一个字段名字(也可以改变类型和默认值) alter table table_name change sorce_col_name dest_col_name type default value; source_col_name指原来的字段名称,dest_col_name 指改后的字段名称 例如: 复制代码 代码如下: alter table Board_Info change IsMobile IsTelphone int(3) unsigned default 1;
3.改变一个字段的默认值 alter table table_name alter column_name set default value; 例如: 复制代码 代码如下: alter table book alter flag set default "0′;
4.改变一个字段的数据类型 alter table table_name change column column_name column_name type; 例如: 复制代码 代码如下: alter table userinfo change column username username varchar(20);
5.向一个表中增加一个列做为主键 alter table table_name add column column_name type auto_increment PRIMARY KEY; 例如: 复制代码 代码如下: alter table book add column id int(10) auto_increment PRIMARY KEY;
7.导出数据 select_statment into outfile”dest_file”; 例如: 复制代码 代码如下: select cooperatecode,createtime from publish limit 10 into outfile”/home/mzc/temp/tempbad.txt”;
8.导入数据 load data infile”file_name” into table table_name; 例如: 复制代码 代码如下: load data infile”/home/mzc/temp/tempbad.txt” into table pad;
9.将两个表里的数据拼接后插入到另一个表里。下面的例子说明将t1表中的com2和t2表中的com1字段的值拼接后插入到tx表对应的 字段里。 例如: 复制代码 代码如下: insert into tx select t1.com1,concat(t1.com2,t2.com1) from t1,t2;