一.准备阶段
#查看数据库
show databases;
#创建名为aaa的数据库编码为'utf8'
create database aaa character set 'utf8';
#选择数据库
use 数据库名;
#创建表
create table project_line(
#主键自增
id int primary key auto_increment comment '主键',
(title)字段名 (varchar(100))字段类型 not null default ''(默认值为空字符) comment '字段注解',
create_at datetime not null default current_timestamp comment '创建时间',
update_at datetime not null default current_timestamp on update current_timestamp comment '更新时间',
create_by bigint not null default 0 comment '创建人',
update_by bigint not null default 0 comment '更新人',
is_delete bigint not null default 0 comment '1为旧数据0为新数据',
) engine=innodb default charset=utf8 comment='给表添加注释';
二.查
#查看所有表
show 表名;
#查询所有字段
select * from 表名;
三.改
#修改字段值,将id为1的一条数据中的字段名1和字段名2进行修改
update 表名 set 字段名1='值1',字段名2='值2' where id=1;
#修改字段类型
alter table 表名 modify column 字段名 类型 comment '注释';
#修改字段名称
alter table 表名 change 旧字段名 新字段名 新数据类型 comment '注释';
#插入字段,并设置默认值
alter table 表名 add column 字段名 类型 not null default 填入默认值 comment '注释';
四.删
#删除表内容并且使id从1开始
truncate table 表名;
五.增
#多行添加
insert into 表名(字段名1, 字段名2, 字段名3, 字段名4) values
(字段名1添加的内容, 字段名2添加的内容, 字段名3添加的内容, 字段名4添加的内容),
(字段名1添加的内容, 字段名2添加的内容, 字段名3添加的内容, 字段名4添加的内容),
(字段名1添加的内容, 字段名2添加的内容, 字段名3添加的内容, 字段名4添加的内容);