*写在前面提醒自己:DOS命令写SQL写完最后一个语句要加分号“;”。
一、删除
delete:删除表中的 行 ,如 delete from 表名 where 字段名=值;
drop:删除索引、表或者数据库,如 drop table 表名;
truncate:删除表中的数据,但表头保留,如 truncate table 表名;
删除 列 参考下面alter用法。
二、插入
insert into:插入新的 行 ;
update:修改 列 数据,如 update 表名 set 列名=新值 where 列名=原值;
alter:添加、修改、删除 列 如
①增加列:alter table 表名 add 列名 数据类型;
②删除列:alter table 表名 drop (column)列名;
③修改列数据类型:alter table 表名 modify (column)列名 新数据类型;
三、设置主键
*只能有一个自增列
alter table 表名
add keyname int auto_increment, add primary key(id);
四、新增列的位置设置
加到首列:
alter table T表名 add column 新列名 datatype not null first;
加到最后:
alter table 表名 add column 新列名 varchar(20) not null;
加到指定位置:
alter table 表名 add 新列名 varchar(20) not null after 指定列;