stuTab表名
显示数据库:show databases;
创建数据库:create database if not exists studb
操作表:use studb
显示表:show tables
创建表:create table if not exists stuTable (id int,name varchar(20),gender varchar(2))ENGINE='innoDB' default charset='utf8';
插入数据:insert into stuTable (id,name,gender) values (1,'yangshaofeng','M
显示信息:SELECT * FROM STUtABLE;
修改: update stuTable set name = 'zhangsan' where id=1;
删除: delete from stuTable where id = 1;
查看表结构:show create table sstuTable;
表的重命名:rename table stuTable to newTable;
删除表: drop table newTable;
删除数据库:drop database stu;
alter 增加字段 删除一个字段 飞字段扩充长度
修改字段或者表的编码 修改字段的名字
设置id可以自增: create table if not exists stuTable(id int not null auto_increment primary key, name varchar(2)not null) engine = 'innodb' default charset = 'utf8';
修改字段类型和名字:alter table stuTable change name name varchar(20) not null;
添加字段:alter table stuTable add(phone text);
根据id查找:select * from stuTable where id = 4;
指查找名字:select name from stuTable where phone ='125650'or phone = '120';
显示个数根据条件:select count(name) from stuTable where phone = '125650' or phone = '120';
模糊查找:select count(name) from stuTable where name like 'gao%';
根据成绩排序(升序):select score from scoretable order by score;
降序: select score from scoretable order by score desc;
最大数:select max(score) from scoretable;
最高得分:select max(score) as '最高分' from scoretable; as是起别名的
最低分:select min(score) as '最低分' from scoretable;
平均分:select avg(score) as '平均分' from scoretable;
分数大于70并且排序:select score from scoretable where score >70 order by score;
limit从1开始取6条:select score from scoretable where score >70 order by score limit 1,6; (1是下标)
查找子字段:select score from scoreTable where stuId =(select id from stuTable where name = 'gaopeng 'limit 1,1);
网友评论