数据库名称:db_01 表名称:tb_01
数据库database相关操作:
show databases; — 显示所有的数据库名称
create database db_01; — 创建数据库
use db_01; — 在数据库db_01中进行操作
delete database db_01; — 删除数据库
数据表table相关操作:
show tables; — 显示当前数据库中所有的表名称
select count(*) from table_01; — 获取表格数据的个数
create table tb_01(id INT, name CHAR(50)); — 创建包含id字段和name字段的数据表
alter table tb_01 add age INT first; — 在表的第一列插入新字段age
alter table tb_01 add age INT after id; — 在表的id字段后面插入新字段age
alter table tb_01 change id newid INT; — 修改字段名称(后面的INT不能为空)
alter table tb_01 modify id CHAR(50); — 修改字段类型(INT改为CHAR)
alter table tb_01 add constraint primary key(id); — 给指定列id添加主键约束
create index ididx on tb_01(id); — 在表tb_01的id字段上创建索引
drop table tb_01; — 删除表
truncate table tb_01; –清除表中的所有数据
表中数据的相关操作:
select * from tb_01; — 查看表中的所有数据
select * from tb_01 where id=1; — 查看表中符合指定查询条件的数据
insert into tb_01 values(1,’Willam’); — 为表中所有字段插入一条数据
insert into tb_01 values(2,’Poul’),(3,’Tomas’); — 向表中插入多条数据
insert into tb_01 (id) values(1); — 为表中的指定字段插入数据
delete from tb_01 where id=1; — 删除表中指定数据