用于基础操作使用,建库删库,建表删表,新增字段,删除字段,新增数据,数据修改,数据查询,添加注释。
1.库 建库create database +库名; 例:create database sit;删库
drop database +库名; 例:drop database sit;2.表 建表:(-- 是注释的意思,这个建表语句可直接复制执行)
create table test3( -- 创建的表名叫test3 id int(10) not null comment '编号', -- 定义字段id未int类型数据且不为空,注释为:编号 name varchar(50) comment '名字', -- 定义字段name为varchar数据类型,注释为:名字 qian decimal(16,6) DEFAULT 5.3 comment '价格', -- 定义字段qian为精准数据类型,注释为:价格 love char(50) comment '爱好', -- 定义字段love为字符类型,注释为:爱好 dile DATETIME comment '死亡时间', -- 定义字段dile为时间类型(精确到秒),注释为:死亡时间 birsday DATE comment '生日', -- 定义字段birsday为时间类型(精确到日),注释为:生日 jieshao text comment '介绍', -- 定义字段jieshao为文本类型,注释为:介绍 primary key (id) -- 定义字段id为主键 )comment '英雄表'; -- 注释表为:英雄表删表:
drop table +表名; drop table test3; -- 删除表(运行后这个表就不存在了) delete from +表名; delete from test2; -- 清空表(运行后这个表里的数据就不存在了,但是表还在)3.列
alter table 表名add column 字段名 字段类型; alter table test3 add column addthing varchar(20); -- 在最后一行加入列 alter table 表名add column 字段名 字段类型 after 字段名; alter table test3 add column spall varchar(20) after love; -- 在指定字段后面增加列 alter table 表名add column 字段名 字段类型 first; alter table test3 add column fitlin varchar(20) first; -- 在第一行加入字段4.增
INSERT INTO 表名(`字段名`, `字段名`, `字段名`, `字段名`, `字段名`, `字段名`, `字段名`) VALUES (对应类型的数据, (对应类型的数据, (对应类型的数据, (对应类型的数据, (对应类型的数据,(对应类型的数据, (对应类型的数据); INSERT INTO dev.test3(`id`, `name`, `qian`, `love`, `dile`, `birsday`, `jieshao`) VALUES (3, '2', 3.550000, '2', '2022-06-23 13:40:15', '2022-06-01', 'SFDSD');5.删
delete from 表名where 列名= 对应的内容; delete from test3 where id = 2; -- 删除指定行 alter table 表名drop column 列名; alter table test3 drop column firstlin; -- 删除列6.改
update 表名set 列名 = 要修改的内容 where 列名= 对应的内容; update test3 set jieshao = 'hhh' where id = 1; -- 修改指定行数据7.查
select t.* from test3 t; select 别称.* from 表名 别称; -- 查整个表数据 select 别称.* from 表名 别称 where 字段名= 对应的数据; select t.* from test3 t where jieshao = 'hhh'; -- 查指定行所有数据 select t.id,t.qian,t.name,t.jieshao from test3 t where t.jieshao = 'hhh'; -- 查询指定数据8.注释
alter table 表名modify column 字段名 字段类型 comment 要添加的注释; alter table test3 modify column firstlin varchar(20) comment '第一哦'; -- 字段创建好了再修改注释 alter table 表名comment 要添加的注释; alter table test3 comment '想死表'; -- 修改表注释



