欢迎光临散文网 会员登陆 & 注册

MySQL基础语法

2022-07-12 22:51 作者:啥也不会QAQ-带冰  | 我要投稿

把一些课上做的笔记搬来B站~

-- 创建库

-- create database 数据名 charset=utf8;

-- use 数据库名

-- 创建表

-- create table 表名(

-- 列名1  数据类型 约束类型,

-- 列名2  数据类型 约束类型,

-- .....,

-- 列名n  数据类型 约束类型

-- )

-- 数据类型 int varchar double(18,2) decimal(18,2) datetime

-- 约束类型

-- 主键 primary key

-- 唯一 unique

-- 非空 not null

-- 默认 default

-- foreign key (列名) references 表名2(主键)

-- 添加数据

-- insert into 表名 values(数值1,数值2,....,数值n)

-- 查询数据

-- select * from 表名 where 条件查询

-- 查询学生姓名、电话

-- select 列名1,列名2,....,列名n  from 表名 where 条件查询

-- 修改数据

-- update 表名 set 列名1=数值1,列名2=数值2,....,列名n=数值n where 条件查询

-- 删除数据

-- delete from 表名 where 条件查询

-- 删除数据库

-- drop database 数据库名

-- 条件查询

-- 关系条件  > < >= <= != <> =

-- 逻辑条件   and or not

-- 不连续条件  where 列名 in(数值1,数值2);

-- 连续条件 where 列名 between 开始的值 and 结束的值

-- 空值条件 where 列名 is (not) null

-- 模糊条件 where 列名 like '%%'  _

-- 聚合函数

-- count()统计行数

-- sum(列名) 求和

-- avg(列名) 平均值

-- max(列名) 最大值

-- min(列名) 最小值

-- 排序

-- order by 列名1 asc 升序|desc 降序,列名2 asc 升序|desc 降序


MySQL基础语法的评论 (共 条)

分享到微博请遵守国家法律