2.27-1笔记1

server/2025/2/28 9:11:22/

一、新建表

图片

二、建表语句

create table student( id int primary key , name char(20), sex char(10), age int(3), mobile char(20), class char(10), english int(10), chinese int(10), math int(10) )engine=innodb default charset=utf8; insert into student values (1,'小红','女',23,'13813828824','1719',77,88,98), (2,'小明','男',23,'13713713711','1720',56,66,55), (3,'小李','男',23,'15915913911','1719',78,64,87), (4,'小张','男',23,'15915913912','1720',77,76,77), (5,'小白','女',24,'15915913913','1719',90,89,98), (6,'小陈','女',19,'15915913914','1719',84,100,81), (7,'小钱','女',20,'15915913915',null,45,99,93);

三、操作语句

1、表结构的语句

(1)add  添加字段

格式:ALTER  table   表名  add   字段名  字符类型(字符长度);

案例:ALTER  table   student  add   dcs  int(10);

图片

(2)change 修改字段

格式:ALTER  table   表名  change  源字段名   新字段名  字符类型(字符长度);

案例:ALTER  table   student  change  dcs   hzdcs  int(10);

图片

(3)drop 删除字段

格式:ALTER  table    表名  drop   字段名;

案例:ALTER  table    student  drop   hzdcs ;

图片

(4)rename 修改表名

格式:ALTER  table     表名  rename  新表名 ;

案例:ALTER  table     student  rename  student2 ;

图片

(5)modify     after   字段的调换

格式:

alter  table   表名  modify  源字段名  字符类型(字符长度)  after  表中字段名 ; 

案例:

alter  table   student2  modify  math int(10)  after  name ; 

图片

(6)first  添加字段到第一位

格式:

ALTER  table   表名    add  新字段名  字符类型(字符长度)  first ; 

案例:

ALTER  table   student2    add  no  int(10)  first ; 

图片

2.27-1课堂笔记:

-- select * from student;#查询内容

-- ALTER table student add dcs int(10);#最后添加字段dcs

-- alter table student change dcs hzdcs int(10);#字段改名

-- alter table student drop dsc;#删除字段

-- alter table student rename stu;#改表名
-- select * from stu;
-- alter table stu rename student;
-- alter table student rename s;

-- desc student;#查看字段
-- alter table student modify math int(10) after name;
-- alter table student modify math int(10) after class;
#把字段math移到某字段后面


-- alter table student add num int(10) first;
#在最前面加字段

-- select * from student;
-- select * from s;#查看全部

-- select name as "姓名",math "数学" from s;
#显示某些字段,as可省略


#####查询
-- select name,math,english,chinese from s 
--      where math>80 and english>80 and chinese>80;
#条件查询where

-- alter table s change math m int(10);#改字段名
-- alter table s change english e int(10);
-- alter table s change chinese c int(10);

-- select * from s where id between 2 and 5;
#查id在2到5之间的between

-- select * from s where id in (2,6,8);
#查id包含在2或6或8的

-- select * from s where id not in (2,6,8);
#查id不包含在2或6或8的

-- select * from s where class is null;
#查含空值的

######排序
-- select * from s order by m asc;#升序
-- select * from s order by m desc;#降序

-- select * from s order by age asc,m desc,c desc,e desc;
#多次排序

-- select * from s where m like "8%";#8开头
-- select * from s where m like "%8%";#含8
-- select * from s where m like "%8";#8结尾
-- select * from s where m like "8_";#查看80几
-- select * from s where m like "8__";#查看800多

-- select * from s limit 0,3;#从索引第一个开始取3个数据
-- select * from s limit 4;#索引前4行
#索引=行数-1

-- select max(m) from s;#数学最大值
-- select min(m) from s;#数学最小值
-- select sum(m) from s;#数学求和
-- select avg(m) from s;#数学平均值
-- select count(m) from s;#数学统计个数
-- select DISTINCT(m) from s;#数学去重

-- select class,avg(m) from s group by class;
-- select class,avg(m) from s group by class HAVING m<80;
#求每个班平均数小于80

-- UPDATE s set name="小红帽" where id=1;
-- UPDATE s set name="小红" where id=1;
#将id=1的人name字段改成小红帽
-- select * from s;

######删除
#方法1
-- delete from s where id=100;#删除id=100的数据
#方法2
-- -- truncate sb;#连表带数据全部删掉
#方法3
#drop(前面已讲)
#drop>truncate>delete


#######注释
#ctrl+/注释
#shift+ctrl+/取消注释


#备份
-- create table sb like s;#备份表结构,不复制数据
#备份部分数
#insert into sb(id,age) select id,age from s;
#备份全部数据
#truncate sb;
-- select * from sb;


 


http://www.ppmy.cn/server/171260.html

相关文章

嵌入式硬件篇---常用的汇编语言指令

文章目录 前言汇编语言简介1. 数据传送指令MOVPUSHPOPXCHG 2. 算术运算指令ADDSUBMULDIVINCDEC 3. 逻辑运算指令ANDORXORNOTSHL/SHR 4. 控制转移指令JMPCALLRETJE/JZJNE/JNZJG/JNLEJL/JNGE 5. 比较与测试指令CMPTEST 6. 标志寄存器操作指令STCCLCSTDCLD 7. 字符串操作指令MOVSL…

高效获取淘宝商品信息、数据、价格和销量API接口的实践指南

在电商领域&#xff0c;获取商品的详细信息&#xff08;如价格、销量、库存等&#xff09;对于市场分析、商品选品、库存管理和价格监控等场景至关重要。淘宝开放平台提供了丰富的API接口&#xff0c;帮助开发者和商家高效获取这些数据。本文将详细介绍如何使用淘宝API接口获取…

从“Switch-case“到“智能模式“:C#模式匹配的终极进化指南

当代码开始"思考" 你是否厌倦了层层嵌套的if-else地狱&#xff1f;是否想过让代码像侦探推理一样优雅地解构数据&#xff1f;C#的模式匹配正是这样一把瑞士军刀&#xff0c;从C# 7.0到C# 12&#xff0c;它已悄然进化成改变编程范式的利器。 一、模式匹配的三重境界…

Linux:Shell环境变量与命令行参数

目录 Shell的变量功能 什么是变量 变数的可变性与方便性 影响bash环境操作的变量 脚本程序设计&#xff08;shell script&#xff09;的好帮手 变量的使用&#xff1a;echo 变量的使用&#xff1a;HOME 环境变量相关命令 获取环境变量 环境变量和本地变量 命令行…

DeepSeek实现FunctionCalling调用API查询天气

什么是FunctionCalling Function Calling&#xff08;函数调用&#xff09;是大型语言模型&#xff08;如 OpenAI 的 GPT 系列&#xff09;提供的一种能力&#xff0c;允许模型在生成文本的过程中调用外部函数或工具&#xff0c;以完成更复杂的任务。通过 Function Calling&am…

机器学习数学基础:33.肯德尔和谐系数教程

肯德尔和谐系数教程 一、定义与用途 肯德尔和谐系数&#xff08;Kendall’s W&#xff09;是一种用于衡量多个评价者对一组对象进行评价时&#xff0c;评价结果一致性程度的统计量。它的取值范围在0到1之间。当W \ 0时&#xff0c;表示评价者之间的评价完全不一致&#xff1…

从零到一:如何用阿里云百炼和火山引擎搭建专属 AI 助手(DeepSeek)?

本文首发&#xff1a;从零到一&#xff1a;如何用阿里云百炼和火山引擎搭建专属 AI 助手&#xff08;DeepSeek&#xff09;&#xff1f; 阿里云百炼和火山引擎都推出了免费的 DeepSeek 模型体验额度&#xff0c;今天我和大家一起搭建一个本地的专属 AI 助手。  阿里云百炼为 …

idea 编码设置

新项目 File -> New Projects Setup -> Settings for New Projects… 当前项目 File -> Settings -> Editor-> File Encodings 设置同上即可。