mysql的基础增删改查(一)

修改,操作表:
1、建表:create table MyClass(id int(4) not null primary key auto_increment,name char(20) not null);
2、获取表结构命令: desc 表名,或者show columns from 表名
3、删除表命令:drop table <表名>
4、在表中增加字段:命令:alter table 表名 add字段 类型 其他;
  eg:alter table MyClass add passtest int(4) default '0'
5、在表中删除字段:命令:alter table 表名 drop字段;
  eg:alter table MyClass drop passtest;
6、更改表名:命令:rename table 原表名 to 新表名; eg:rename table myclass to youclass
7、更改字段名:alter table myclass change column degree score double(8,2);

修改,操作数据:
1、插入数据:insert into MyClass values(1,'Tom'),(2,'Joan');或者insert into MyClass(name) values('Tom'),('Joan'); (因为id自增)
2、查询所有行命令: select <字段1,字段2,...> from < 表名 > where < 表达式 >
  eg:select * from MyClass;
3、查询前几行数据: select * from MyClass order by id limit 0,2;或者:select * from MyClass limit 0,2;
4、删除表中数据命令:delete from 表名 where 表达式
  eg:delete from MyClass where id=1;
5、修改表中数据:update 表名 set 字段=新值,… where 条件
  eg:update MyClass set name='Mary' where id=1;
  eg:update myclass set name=concat('s',name);(用函数)

原文地址:https://www.cnblogs.com/fzly-88/p/7206351.html