alter table 库名.表名 add 要添加的字段名 类型;
mysql> alter table tea6 add address varchar(48);
在tea6表的age列之后添加一个gender字段
alter table 库名.表名 add 要添加的字段名 类型 after 要在哪个列后面添加;
mysql> alter table tea6 add gender enum('boy','girl') after age;
将tea6表的gender字段改名为sex,并添加非空约束
alter table 库名.表名 change 原字段名 改字段名 类型 约束条件(可以不添加);
mysql> alter table tea6 change gender sex enum('boy','girl') not null;
删除tea6表中名为sex的字段
alter table 库名.表名 drop 要删除的字段
mysql> alter table tea6 drop sex;
创建tea4表,将其中的id、name作为索引字段
mysql> crente table tea4( id char(6) not null, name varchar(6) not null, age int(3) not null, gender enum('boy','girl') default 'boy', index(id),index(name));
删除tea4表中名称为named的index索引字段
mysql> drop index name on tea4;
针对tea4表的age字段建立索引,名称为 nianling
mysql> create index nianling on tea4(age);
建表时设置PRIMARY KEY主键索引
mysql> CREATE TABLE db2.tea6( id int(4) AUTO_INCREMENT, name varchar(4) NOT NULL, age int(2) NOT NULL, PRIMARY KEY(id));
mysql> load data infile "目录名/文件名" into table 库名.表名 fields terminated by "分隔符" lines terminated by "\n";
mysql> load data infile "/myload/passwd" into table db3.user fields terminated by ":" lines terminated by "\n";
导出数据
mysql> elect *from 库名.表名 into outfile "/目录名/文件名";
mysql> elect *from db3.user into outfile "/myload/user1.txt";
插入部分字段的值
mysql> insert into 表名(字段名) values(字段值);
mysql> insert into stu_info(name,age) values('Jerry',27);
将stu_info表中所有性别为“boy”的记录的age设置为20
mysql> update 表名 set 字段名=字段值 where 字段名=字段值;
mysql> update stu_info set age=10 where gender='boy';
删除stu_info表中年龄小于18的记录
mysql> delete from 表名 where 字段名 < 字段值;
mysql> delete from stu_info where age < 18;