1.实现一对多查询:
select teacher.teaname from student join teacher on(student.tid = teacher.id)where (student.id='1');
2. 创建数据库:create database `数据名` [数据库选项:charset=utf8] [if not exists `数据名`]//不存在则创建
2.1删除数据库:drop database `match` if exists `match`;//存在则删除
3.查询数据库:show databases;
show databases like 'match';
show databases like '%match';能匹配到xxxxmatch数据库
show databases like 'm_tch';//能匹配到match数据库
like后面使用字符串作为过滤原则。mysql中的字符串,使用单引号进行包裹!(也是支持双引号,但是双引号有特别的含义,因此不建议使用)
字符串中可以使用 通配符!(通用匹配符号)
1.% 百分号,匹配任意字符的任意数量!
2._ 下划线,匹配任意字符的一次出现!//'____'能匹配到四个字符的数据库
4.查看某个库的定义: show create database `库名`;
5.删除数据库:drop database `库名`;
6.选择数据库:use `testmvc`;
7.设置编码:set names gkb;//解决黑框框乱码问题
8.创建数据表: create table `match` (
stu_id int primary key auto_increment,
stu_no varchar(10) default NULL,
stu_name varchar(30) default NULL,
intime timestamp default current_timestamp
);
)[表选项] primary key autoincreament,
9.查看表:show tables [like ‘匹配字符串’];
10.查看表结构: desc `表名`;
11.删除表:drop table [if exists] `表名`;
12.修改表选项:alter table 表名 选项=新值 例子:alter table `match` engine=innodb;
13.重命名表:rename table `旧表名` to `新表名`;
14.添加字段:alter table `表名` add column 字段定义 位置 例子:alter table `user` add column height int after `username`;
15.删除字段: alter table `表名` drop column `字段名`;
16.修改字段:
1.字段修改定义同时改名:alter table 表名 change column 旧字段名 新字段定义(名字,类型,属性) 位置
例子:alter table `student` change column id stu_id int first;
2.字段只修改定义:alter table 表名 modify column 字段名 新的定义(类型,属性)
例子:alter table `user` modify column `username` varchar(50) not null;
17.增加数据:
insert into 表名 (`id`,`username`,`pwd`,`email`) values ($id,'$username','$pwd','$email');
//可以省略字段名列表部分,但是字段值必须要一一对应
18.查看记录:select 字段列表 from 表名 [where 条件表达式]//字段列表可以用*代替
例子:select `id`,`username`,`pwd`,`email` from `user` [where id=$id];
select * from tb where password is (not) null;
19.删除记录:delete from `表名` [where 条件] //where条件不在时删除表中所有数据 慎重!!!
20.修改(更新)记录:update `表名` set `字段`='值', `字段`='值' [where 条件表达式];