当前位置:网站首页>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
边栏推荐
- [数据可视化] 图表设计原则
- 时间戳转换为日期格式、获取当前时间戳
- 异常:try catch finally throws throw
- Ali P7 bask in January payroll: hard to fill the, really sweet...
- I caught a 10-year-old Ali test developer, and after talking about it, I made a lot of money...
- 小程序onPageNotFound的坑
- 关于科研学习中的几个问题:如何看论文?如何评价工作?如何找idea?
- 云原生-FRP内网穿透(详解)使用云服务器将内网集群服务暴露至公网(二)
- BEVDepth: Acquisition of Reliable Depth for Multi-view 3D Object Detection Paper Notes
- 容器技术真的是环境管理的救星吗?
猜你喜欢
Lens filter---about day and night dual-pass filter
Mysql数据库安装配置详细教程
Mysql.慢Sql
【21天学习挑战赛】折半插入排序
Apache Commons Configuration Remote Code Execution Vulnerability (CVE-2022-33980) Analysis & Reproduction
SAS data processing technology (1)
软件测试证书(1)—— 软件评测师
sed of the Three Musketeers of Shell Programming
input输入框超出部分用省略号表示以及判断内容是否有超出(PC端)
Dump file generation, content, and analysis
随机推荐
Dump文件生成,内容,以及分析
apache+PHP+MySQL+word press,安装word press时页面报错?
sed of the Three Musketeers of Shell Programming
【C语言】探索数据的存储(整形篇)
数据分析面试手册《统计篇》
nodejs项目连接mysql数据库
HW-蓝队工作流程(1)
Elastic scaling of construction resources
Pagoda Test-Building PHP Online Mock Exam System
HW-常见攻击方式和漏洞原理(2)
How to do patent mining, the key is to find patent points, in fact, it is not too difficult
使用 BeanUtils 做属性拷贝,性能有点拉胯!
两个数组的交集
构建检测,无规矩不成方圆
微信小程序通过URL Scheme动态的渲染数据
@Autowired注入RedisCache报错空指针
22/8/9 Collection of Greedy Problems
2022.8.10-----leetcode.640
如何做到构建的提速,再提速
networkmanager无法打开