本文共 2762 字,大约阅读时间需要 9 分钟。
create database 数据库名;
数据库是存储数据的主要容器,使用适当的名称来组织你的数据。
show databases;
这将列出你当前正在使用的所有数据库。
drop database 数据库名;
谨慎操作,删除数据库会永久丢失所有数据。
use 数据库名;
切换到指定数据库后,你的后续操作将针对该数据库进行。
create table 表名(字段名1 类型1 [, ... 字段名n 类型n]);
create table myTable(id int(4) not null primary key auto_increment,name char(255),score float(8,2));
drop table 表名;
删除表会移除其所有数据和结构。
insert into 表名[(字段名1[, ... 字段名n])] values (值1[, ... 值n]);
insert into myTable (id,name,score) values(1,"tom",93.65);
select 字段1, 字段2, ... from 表名 where 表达式;
select * from myTable;
select * from myTable order by 字段名 limit 数量,偏移量;
select * from myTable order by id limit 0,2;
select * from 表名 where 字段名 > 条件值;
select * from myTable where score > 60;
create table 表名(字段名1 类型1 [, ... 字段名n 类型n]);
create table myTable2(id int(4) not null primary key,name char(255),grade double(8,2));
select * from 表名1, 表名2 where (字段名1 > 60 and 字段名2 > 60);
select * from myTable,myTable2 where (score > 60 and grade > 60);
delete from 表名 where 条件表达式;
delete from myTable2 where id=4;
update 表名 set 字段名 = 新值 where 条件表达式;
update myTable2 set name="小白" where id=3;
alter table 表名 add 字段名 类型 [默认值];
alter table myTable2 add brother int(4) default 0;
rename table 原表名 to 新表名;
rename table myTable to myNewTable;
select ah_day_table.id as ah_day_table_id, GROUP_CONCAT('系统订单',ah_order_table.id,'',ah_order_table.orderStatus) as ah_order_table_need_datafrom ah_day_table join ah_order_table on ah_day_table.orderPersonName = ah_order_table.orderPersonNamegroup by ah_day_table.id;
update 表名 set 字段名 = 表达式 when 条件1 then 值1 when 条件2 then 值2 ... end where 条件表达式;
update ah_sf_table setah_sf_table.lastLogisticsStatus = casewhen billCode='运单号A' then '退回签收'when billCode='运单号B' then '退回签收'ENDWHERE billCode IN ('运单号A','运单号B');
insert into 表名 (字段名1[, ... 字段名n]) values (值1[, ... 值n]);
insert into ah_day_table(orderPersonName,orderPhone,orderTime,orderCode,orderCount,orderContent,orderMark,orderAddress,orderIP,orderPrice) values( '小王', '137xxxxxxxx', '2021-05-31 17:03:29','xxxx', '1','xxxx', 'xxxx','xxxx','xxxxx','19.0'), ('小张', '137xxxxxxxx', '2021-05-31 17:03:29','xxxx', '2','xxxx', 'xxxx','xxxx', 'xxxxx','19.0'), ('小李', '137xxxxxxxx', '2021-05-31 17:03:29','xxxx', '3','xxxx', 'xxxx','xxxx', 'xxxxx','19.0'), ('小孙', '137xxxxxxxx', '2021-05-31 17:03:29','xxxx', '4','xxxx', 'xxxx','xxxx', 'xxxxx','19.0');
delete from 表名 where 字段名 in (值1, 值2, ...);
delete from ah_day_table where id in (20,21,22,23);
以上操作可以帮助你高效管理数据库,熟练掌握这些命令将显著提升你的数据库操作能力。
转载地址:http://ocbfk.baihongyu.com/