当前位置:网站首页>从零开始学 MySQL —数据库和数据表操作
从零开始学 MySQL —数据库和数据表操作
2022-07-01 18:42:00 【InfoQ】

- 数据库操作:删除数据库、修改数据库。
- 数据表操作:重命名表、删除表、指定位置增加一列数据、删除一列、重命名一列、更改数据类型、删除一行记录。
https://github.com/rongweihe/MoreThanCode/tree/master/mysql_shiyan#打开 MySQL 服务
sudo service mysql start
#使用 root 用户登录
mysql -u rootsource /home/MySQL_05_01.sql;

【文章福利】另外小编还整理了一些C++后端开发面试题,教学视频,后端学习路线图免费分享,需要的可以自行添加:
学习交流群点击加入~
群文件共享
小编强力推荐C++后端开发免费学习地址:
C/C++Linux服务器开发高级架构师/C++后台开发架构师

RENAME TABLE 原名 TO 新名字;
ALTER TABLE 原名 RENAME 新名;
ALTER TABLE 原名 RENAME TO 新名;use mysql_shiyanRENAME TABLE table_1 TO table_2;
DROP TABLE 表名字;DROP TABLE table_2;
3.3 增加一列
对表结构的修改,会实际影响数据表的结构,有时候一些小的错误会造成不可挽回的后果,所以谨慎细心操作。在实际生产环境中,一定要得到上级领导的许可,否则不要轻易修改。
我们来看看,在表中增加一列的语句格式为:
ALTER TABLE 表名字 ADD COLUMN 列名字 数据类型 约束;
ALTER TABLE 表名字 ADD 列名字 数据类型 约束;ALTER TABLE employee ADD height INT(4) DEFAULT 170;
ALTER TABLE employee ADD weight INT(4) DEFAULT 120 AFTER age;
ALTER TABLE employee ADD test INT(10) DEFAULT 11 FIRST;
3.4 删除一列
ALTER TABLE 表名字 DROP COLUMN 列名字;
或:ALTER TABLE 表名字 DROP 列名字;ALTER TABLE employee DROP test;
ALTER TABLE 表名字 CHANGE 原列名 新列名 数据类型 约束;ALTER TABLE employee CHANGE height shengao INT(4) DEFAULT 170;
3.6 改变数据类型
ALTER TABLE 表名字 MODIFY 列名字 新数据类型;UPDATE 表名字 SET 列1=值1,列2=值2 WHERE 条件;UPDATE employee SET age=25 ,salary=20000 WHERE name='xiaowei';
3.8 删除一行记录
DELETE FROM 表名字 WHERE 条件;DELETE FROM employee WHERE name='xiaohong';
4、总结
参考资料

边栏推荐
- 中英说明书丨人可溶性晚期糖基化终末产物受体(sRAGE)Elisa试剂盒
- 实例讲解将Graph Explorer搬上JupyterLab
- Lumiprobe 自由基分析丨H2DCFDA说明书
- Database foundation: select basic query statement
- C端梦难做,科大讯飞靠什么撑起10亿用户目标?
- Today, with the popularity of micro services, how does service mesh exist?
- Taiaisu M source code construction, peak store app premium consignment source code sharing
- docker 部署mysql8.0
- Viewing the whole ecology of Tiktok from a macro perspective
- 机械设备行业数字化供应链集采平台解决方案:优化资源配置,实现降本增效
猜你喜欢

Lake Shore 连续流动低温恒温器传输线

市值蒸发740亿,这位大佬转身杀入预制菜

MySQL common graphics management tools | dark horse programmers

Improve yolov5 with gsconv+slim neck to maximize performance!

Lumiprobe 细胞成像研究丨PKH26细胞膜标记试剂盒

Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?

Lake Shore—OptiMag 超导磁体系统 — OM 系列

Privacy sandbox is finally coming

Cdga | if you are engaged in the communication industry, you should get a data management certificate

Today, with the popularity of micro services, how does service mesh exist?
随机推荐
Huawei cloud experts explain the new features of gaussdb (for MySQL)
After studying 11 kinds of real-time chat software, I found that they all have these functions
Altair HyperWorks 2022 software installation package and installation tutorial
Solution of intelligent supply chain management platform in aquatic industry: support the digitalization of enterprise supply chain and improve enterprise management efficiency
Once the SQL is optimized, the database query speed is increased by 60 times
Lefse analysis
Appgallery connect scenario development practice - image storage and sharing
Li Kou daily question - Day 32 -1232 Dotted line
Go language self-study series | go language data type
Lumiprobe 亚磷酰胺丨六甘醇亚磷酰胺说明书
Qt中的QFile读写文件操作
JS find the next adjacent element of the number in the array
网易游戏,激进出海
3. "Create your own NFT collections and publish a Web3 application to show them" cast NFT locally
Leetcode-21 combines two ordered linked lists
前4A高管搞代运营,拿下一个IPO
斯坦福、Salesforce|MaskViT:蒙面视觉预训练用于视频预测
Cdga | if you are engaged in the communication industry, you should get a data management certificate
R language uses the DOTPLOT function of epidisplay package to visualize the frequency of data points in different intervals in the form of point graph, and uses PCH parameters to customize the shape o
【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?