数据库结构操作
1.查看数据库
show databases;
2.创建数据库
create database 数据库名;
3.进入数据库
use 数据库名;
4.创建表
craete table 表名(字段1,字段2,字段3,…);
5.查看表结构
desc 表名;
6.查看表
select * from 表名;
7.删除数据库
drop database 数据库名;
8.删除表
drop table 表名;
*值得注意的是:用drop删除的都不可恢复
9.删除表的某一列
alter table 表名 drop cloumn 列名;
删除语句:
delete from 表名 where 条件;
修改语句:
update 表名 set 字段名=值 where 条件;
添加语句:
insert into 表名(字段1,字段2,字段3,…) value(字段1,字段2,字段3,…);
查询语句:
1.条件查询
当…时
where
select * from table where 条件表达式;
当..时(与上面的区别是这里可以多个条件,用逗号隔开)
where in
select * from table where in (条件表达式1,条件表达式2…);
当…和…时(这里只能有2个条件表达式)
where and
select * from table where 条件表达式1 and 条件表达式2;
where or当…或…时
select * from table where 条件表达式1 or 条件表达式2;
当不是…时
where not in
select * from table where not in (条件表达式1,条件表达式2…);
当在…和…之间时
where between