一、有关数据库的命令:
1、查看数据库: show databasese;
2、添加数据库: create database 库名;
3、删除数据库: drop database 库名;
4、使用某数据库: use 库名;
5、查看该库下表: show tables;
二、库下的表添加,删除,修改:
1、添加数据库:
create table 表名(
列1名 类型,
列2名 类型,
列3名 类型,
列4名 类型,
列5名 类型,
);
2、 查看表:
describe 表名;
3、删除表:
drop table 表名
4、修改表名:
alter table 旧名 rename 新名;
三、表内列的命令
1、查看表:
describe 表名;
2、添加列:
alter table 表名 add 列名 数据类型;
3、删除列:
alter table 表名 drop 列名;
4、修改列里的内容:
alter table 表名 change 列名 旧名 新名 类型;
四、查看表的数据
1、select *from 表名; //查看的是全部数据
select 列名,列名,列名……from 表名;//查看某一列的数据
2、插入数据
insert into 表名 values(值1,值2……【表里有几列,就插入几列数据】)
insert into 表名 (列1名,列2名……)values(值1,值2……【表示在指定的第几列插入数据】);
3、where语法
select * from 表名 where 查找的列名=“具体内容”
多个筛选条件:
select *from 表名 where 列=“” and 列名=‘’” or 列名>xx
null字段的判断
select * from 表名 where 列名 is null ;
select * from 表名 where 列名 is not null ;
select distinct去掉重复查询结果
select distinct 列名,列名,列名……from 表名;
表内数据排序
select * from 表名 order by 列名asc||desc,列名asc||desc,……;
数据的筛选
select * from 表名 [where子句][order by句子] limit[offset],rowCount;
代表的意思:
offset:查询结果的起始位置,,第一条记录的其实是0
rowcount:从offset位置开始,获取的记录条数;
注意:
limit rowCount = limit 0,rowCount;
insert和select组合使用:
insert into 表名 select 列1 ,列2,…… from 表名2;
更新数据库:
修改单列:
update 表名 set 列名=“” where ;
修改多列:
update 表名 set 列1= ,列2=…… where ;