SQL语句

DML:

数据操作语言,增删改查数据,包括insert,delete,update,select

添加语句
insert into 表名 (字段名,字段名,字段名...) values (参数,参数,参数...)
批量添加
insert into 表名 (字段列表) values (参数列表),(参数列表),(参数列表)...
删除语句
delete from 表名 where 字段名 = 参数 #where表示条件,可有可无,下同
truncate 表名称; 删除整张表的数据
批量删除
delete from 表名 where 字段名 in (参数,参数,参数...)
delete from 表名 where 字段名 = 参数 or 字段名 = 参数 or ...
查询语句
select 字段列表 from 表名 where ...
批量查询
select 字段列表 from 表名 where in ()
select 字段列表 from 表名 where 字段名 = 参数 or 字段名 = 参数 or ...
修改语句
update  表名 set 字段名1 = 参数1,字段名2 = 参数2,字段名3 = 参数3,... where ...
批量修改
#修改为相同数据
update 表名 set 字段名1 = 参数1,字段名2 = 参数2,字段名3 = 参数3,...... where 字段名 in(参数,参数,参数...)
update 表名 set 字段名1 = 参数1,字段名2 = 参数2,字段名3 = 参数3,...... where 字段名 = 参数 or 字段名 = 参数 or...

DDL:

数据定义语言,定义库,表结构,包括creat、drop、alter等

数据库操作

1、查看所有数据库

show databases;

2、指定使用某个数据库

use 数据库名;

3、创建数据库

create database 数据库名;

create database 数据库名 charset 'utf8'; #在mysql中字符集名称不要使用utf-8

create database 数据库名 charset 'gbk';

4、删除数据库

drop database 数据库名;
表格操作

5、查看某个库下的所有表格

show tables from 数据库名

6、创建表格

create table 表名(
	字段名1 数据类型,
    字段名2 数据类型,
    ...
)

7、删除表格

drop table 【数据库名】 表名称; #【】中的可有可无,下同

8、查看某个表结构

describe 【数据库名】 表名称;
desc 【数据库名】 表名称

9、增加一列

alter table 表名称 add【column】字段名 数据类型;
alter table 表名称 add【column】字段名 数据类型 first;
alter table 表名称 add【column】字段名 数据类型 after 另一个字段名;

10、删除一列

alter table 表名称 drop 【column】字段名

11、修改列数据类型

alter table 表名称 modify 【column】字段名 行数据类型

12、修改列名

alter table 表名称 change 【coulumn】旧字段名 新字段名 新数据类型

13、修改列的位置

alter table 表名称 modify 字段名 数据类型 first;
alter table 表名称 modify 字段名 数据类型 after 另一个字段名;

14、修改表名称

alter table 旧表名称 rename 新表名称;
rename table 旧表名称 to 新表名称;
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值