当前位置:网站首页>从零开始学 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 root
source /home/MySQL_05_01.sql;


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

RENAME TABLE 原名 TO 新名字;
ALTER TABLE 原名 RENAME 新名;
ALTER TABLE 原名 RENAME TO 新名;
use mysql_shiyan
RENAME 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、总结
参考资料

边栏推荐
- Livedata postvalue will "lose" data
- Salesmartly has some tricks for Facebook chat!
- 2. Create your own NFT collections and publish a Web3 application to show them start and run your local environment
- B2B e-commerce platform solution for fresh food industry to improve the standardization and transparency of enterprise transaction process
- 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
- bean的生命周期核心步骤总结
- Viewing technological changes through Huawei Corps (VI): smart highway
- Dlib+Opencv库实现疲劳检测
- Lake Shore 连续流动低温恒温器传输线
- 组队学习! 14天鸿蒙设备开发“学练考”实战营限时免费加入!
猜你喜欢
市值蒸发740亿,这位大佬转身杀入预制菜
小红书上的爱情买卖
OpenAI|视频预训练 (VPT):基于观看未标记的在线视频的行动学习
Altair HyperWorks 2022软件安装包和安装教程
Games202 operation 0 - environment building process & solving problems encountered
C端梦难做,科大讯飞靠什么撑起10亿用户目标?
生鲜行业B2B电商平台解决方案,提高企业交易流程标准化和透明度
More information about M91 fast hall measuring instrument
SuperVariMag 超导磁体系统 — SVM 系列
AI 训练速度突破摩尔定律;宋舒然团队获得RSS 2022最佳论文奖
随机推荐
Huawei game failed to initialize init with error code 907135000
Superoptimag superconducting magnet system - SOM, Som2 series
R language ggplot2 visualization: visualize the line graph and add customized Y-axis label information to the line graph using the labels function
摄像头的MIPI接口、DVP接口和CSI接口[通俗易懂]
Usage and underlying implementation principle of PriorityQueue
How to operate technology related we media well?
Lumiprobe 细胞成像研究丨PKH26细胞膜标记试剂盒
Summary of the core steps in the life cycle of beans
ES6数组方法find()、findIndex()的总结「建议收藏」
MySQL common graphics management tools | dark horse programmers
MySQL常用图形管理工具 | 黑马程序员
毕业总结
Lake shore M91 fast hall measuring instrument
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
2020,最新手机号码手机验证正则表达式,持续更新
R language epidisplay package ordinal or. The display function obtains the summary statistical information of the ordered logistic regression model (the odds ratio and its confidence interval correspo
【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
Redis 实现限流的三种方式
More information about M91 fast hall measuring instrument
Qt中的QFile读写文件操作