select 从数据库中提取数据
update 跟新数据库中的数据
delete 从数据库删除数据
insert into 向数据库中插入新数据
create database 创建新数据库
alter datebase 修改数据库
create table 创建新表
alter table 改变数据库表
drop table 删除表
create index 创建索引
drop index 删除索引
CREATE TABLE `tb_stu9` (
`id` int(20) NOT NULL AUTO_INCREMENT COMMENT '默认自动增长',
`name` varchar(20) NOT NULL COMMENT '姓名',
`age` int(3) NOT NULL COMMENT '年龄',
`sex` varchar(2) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
mysql模糊查询
select * from 表名 where 字段值 like '%凯%';
左边有百分号是查以'凯'结尾的,
右边有百分号是查以'凯'开头的
两边都有百分号包含'凯'的都查出来;
创建表
CREATE TABLE `tb_user_role` (
`user_id` int(20) NOT NULL,
`role_id` int(20) NOT NULL,
PRIMARY KEY (`user_id`,`role_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
create table `tb_u_r`(
`user_id` int(20) not null,
`role_id` int(20) not null,
primary key(`user_id`, `role_id`))
engine = InnoDb DEFAULT CHARSET = utf8;
create table student(
`id` int(20) not null,
`name` char(10) not null,
primary key (`id`)
)ENGINE = InnoDB DEFAULT CHARSET=utf8;这个地方是utf8不是utf-8
简单触发器,简单的添加触发,像student表中加数据时,自动向grade表中加入一条数据
先创建一张学生表,
CREATE TABLE `student` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` char(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
创建一个成绩表
CREATE TABLE `grade` (
`xueke` char(10) DEFAULT NULL,
`grade` int(10) DEFAULT NULL,
`id` int(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
触发器
每当加入一个学生的时候,就会触发触发器,自动加入一行学生但是没有成绩,
create trigger aaa
after insert on student for each row
begin
insert into grade(id)
values(new.id);
update 跟新数据库中的数据
delete 从数据库删除数据
insert into 向数据库中插入新数据
create database 创建新数据库
alter datebase 修改数据库
create table 创建新表
alter table 改变数据库表
drop table 删除表
create index 创建索引
drop index 删除索引
CREATE TABLE `tb_stu9` (
`id` int(20) NOT NULL AUTO_INCREMENT COMMENT '默认自动增长',
`name` varchar(20) NOT NULL COMMENT '姓名',
`age` int(3) NOT NULL COMMENT '年龄',
`sex` varchar(2) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
mysql模糊查询
select * from 表名 where 字段值 like '%凯%';
左边有百分号是查以'凯'结尾的,
右边有百分号是查以'凯'开头的
两边都有百分号包含'凯'的都查出来;
创建表
CREATE TABLE `tb_user_role` (
`user_id` int(20) NOT NULL,
`role_id` int(20) NOT NULL,
PRIMARY KEY (`user_id`,`role_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
create table `tb_u_r`(
`user_id` int(20) not null,
`role_id` int(20) not null,
primary key(`user_id`, `role_id`))
engine = InnoDb DEFAULT CHARSET = utf8;
create table student(
`id` int(20) not null,
`name` char(10) not null,
primary key (`id`)
)ENGINE = InnoDB DEFAULT CHARSET=utf8;这个地方是utf8不是utf-8
简单触发器,简单的添加触发,像student表中加数据时,自动向grade表中加入一条数据
先创建一张学生表,
CREATE TABLE `student` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` char(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
创建一个成绩表
CREATE TABLE `grade` (
`xueke` char(10) DEFAULT NULL,
`grade` int(10) DEFAULT NULL,
`id` int(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
触发器
每当加入一个学生的时候,就会触发触发器,自动加入一行学生但是没有成绩,
create trigger aaa
after insert on student for each row
begin
insert into grade(id)
values(new.id);
end;
文章中参考了别人的配置命令,地址https://www.cnblogs.com/zhangzhongxian/p/7070277.html