当前位置:网站首页>Use mysql statement to operate data table (table)
Use mysql statement to operate data table (table)
2022-08-11 00:37:00 【SSS4362】
使用mysql语句操作数据表(table)
1 前提
1.1 分析
选择你要操作的数据库,That is, you need to add a new table in that database、删除表等操作
1.2 基本语法
USE 需要操作的数据库名称;
1.3 示例mysql语句
USE classTest01;
/*这个mysql的指令,不是标准sql语句*/
1.4 示例sqlA screenshot of the execution of the statement
2 sqlstatement to create a new data table
2.1 基本语法
CREATE TABLE [IF NOT EXISTS] `数据表名字` (
列名1 数据类型 该列所需约束,
列名2 数据类型 该列所需约束,
.....
列名n 数据类型 该列所需约束,
)character set 字符集 collate 校对规则 engine (存储)引擎;
/*
每个字段/Separate columns with commas
Tables can also specify character sets and collation rules,若没有写,The default is to inherit the character set and collation rules of the database where it is located
*/
2.2 创建一个名称为student的数据表(Character set and collation are inherited from the data table by default
2.2.1 navicatGraphical interface display
a Select the database where you want to create the table,并且双击它
b Right-click on the table,Then double-click New Table
c Set the field properties of the data table
d 点击保存按钮
e Give the new data table a name
f 查看是否新建成功
2.2.2 DOS界面
a mysql对应的sql语句
CREATE TABLE IF NOT EXISTS student02 (
name varchar(10) PRIMARY KEY;
);
b mysql对应的sqlA screenshot of the statement running example
2 mysqlThe statement queries the current structure of a data table
2.1 基本语法
SHOW CREATE TABLE 数据表名称;
2.2 示例mysql语句
SHOW CREATE TABLE student02;
2.3 示例mysqlA screenshot of the statement in action
3 sqlThe statement queries which data tables are under the current database
3.1 基本语法
SHOW TABLES;
/*
SELECT database()You can get which database is currently operating
*/
3.2 示例sql语句
SHOW TABLES;
3.3 示例mysqlA screenshot of the statement in action
4 sql语句修改数据表
4.1 sqlStatement operations modify field properties
4.1.1基本语法
ALTER TABLE 数据表名称 MODIFY COLUMN 字段名称 The part you need to modify;
/*
The part you need to modify can be the length of the data type、数据类型、默认值,约束等
*/
4.1.2 示例mysql语句
ALTER TABLE student02 MODIFY COLUMN age int(15) DEFAULT 0;
/*
更改student02这个表中的age字段的int类型的长度为15 去掉非空,Added default values0
*/
4.1.3 示例mysqlA screenshot of the statement in action
a 修改前
b 修改后
4.2 sqlThe statement modifies the current character set of the data table
4.2.1基本语法
ALTER TABLE 数据表名称 CHARACTER SET 修改后的字符集;
4.2.2 示例mysql语句
ALTER TABLE student02 CHARACTER SET gbk;
4.2.3 示例mysqlA screenshot of the statement in action
执行alter语句之前
执行alter语句之后
5 sqlThe statement deletes an existing data table
5.1 基本语法
DROP TABLE [IF EXISTS] The name of an existing data table;
/*
[]The content in parentheses is optional,一般加上
如果不加上,Then delete the non-existing data table will appearERROR 1051 (42S02): Unknown table 'classtest01.student03'
Plus only a warning will appear
Query OK, 0 rows affected, 1 warning (0.00 sec)
当时0 rowsrow affected,Indicates that the statement was not deleted successfully(There is no such table in the currently operating database)
If a prompt appears after deletionQuery OKIt means the deletion is successful
*/
5.2 示例sql语句
DROP TABLE IF EXISTS student02;
5.3 示例sqlA screenshot of the statement in action
边栏推荐
- How to easily obtain the citation format of references?
- YOLOv5的Tricks | 【Trick10】从PyTorch Hub加载YOLOv5
- 使用mysql语句操作数据表(table)
- Jvm. Profiling tools (jconsole, jvisualvm, arthas, jprofiler, mat)
- 详谈二叉搜索树
- C# using timer
- 22/8/9 Collection of Greedy Problems
- 91.(cesium之家)cesium火箭发射模拟
- 鲲鹏编译调试及原生开发工具基础知识
- Difference Between Image Recognition and Semantic Segmentation
猜你喜欢
【ASM】字节码操作 ClassWriter COMPUTE_FRAMES 的作用 与 visitMaxs 的关系
二维数组实战项目--------《扫雷游戏》
“蔚来杯“2022牛客暑期多校训练营3 DF题解
"NIO Cup" 2022 Nioke Summer Multi-School Training Camp 2 DGHJKL Problem Solution
使用mysql语句操作数据表(table)
YOLOv5的Tricks | 【Trick13】YOLOv5的detect.py脚本的解析与简化
地下管廊可视化管理系统搭建
C# using timer
Elastic scaling of construction resources
关于编程本质那些事
随机推荐
Lens filter---about day and night dual-pass filter
Shell编程三剑客之sed
Dump文件生成,内容,以及分析
分库分表ShardingSphere-JDBC笔记整理
Mysql. Slow Sql
如何破坏Excel文件,让其显示文件已损坏方法
sed of the Three Musketeers of Shell Programming
【redis】发布和订阅消息
[GXYCTF2019]BabySQli
More parameter exposure of Pico 4: Pancake + color perspective, and Pro version
[21天学习挑战赛——内核笔记](五)——devmem读写寄存器调试
J9数字论:DAO治理更像一种生态过程:治理原生于网络,不断演变
异常和异常处理机制
3d打印出现stl文件物体不是流形,意味着不是水密体...解决办法
word 设置标题前分页
二维数组实战项目--------《扫雷游戏》
Navicat 16-数据库工具
ADC和DAC记录
只会懒汉式和饿汉式 你还不懂单例模式!
I caught a 10-year-old Ali test developer, and after talking about it, I made a lot of money...