二、增删改查

增加行:
insert  into  msg(id,age,name,content) values (1,25,’zhangsan’’lihai’);
insert into mugua.category  select  cat_id,cat_name,parent_id  from  shop.category;      shop.category表中导入数据到mugua.category表中(前提是列明得一样)
增加列:
alter table 表明 add 列声明
增加的列默认是在表的最后一列。
 
可以用after来声明新增的列在哪一列后面
alter table 表明 add 列声明 after name;
如果新增的列想放在第一列
alter table 表明 add 列声明 first;
删:
delete from msg   where id = 1;
删除列:
alter table 表名 drop 列名;
改:
update msg set id = 2,content = ‘xili’  where name = 'zhangsan';
修改列:
alter table 表名 change 被改变的列名 列声明
如:
alter table boy change height height smallint not null default 180;
查:
select * from msg;
select id,title from msg;
select id,title from msg where id  > 2;
select  name  as  ‘姓名’  from  msg;(别名)
select  ‘产品价格’*1.2  from  msg;(使用数学计算将msg的产品价格列乘以1.2)
select  substr(productid,1,6)  from  msg;(使用函数substr对MSG表格取子串,1—6字符)
select  distinct(字段名) from  msg;(使用函数distinct去除重复)
原文地址:https://www.cnblogs.com/steven9898/p/11339351.html