当前位置:网站首页>Addition, deletion, modification and query of MySQL advanced table
Addition, deletion, modification and query of MySQL advanced table
2022-04-22 10:25:00 【JanYork_ Little Jane】
Modify the name of the table
ALTER TABLE student RENAME TO stu;
TO It can be omitted .
ALTER TABLE The old name of the table RENAME The new name of the table ;
This statement modifies the name of the table , In fact, we usually use it in the terminal , There is no need to use commands with visualization tools .
Modify fields
ALTER TABLE stu CHANGE email mail VARCHAR(50) NOT NULL ;
-- ALTER TABLE Table name CHANGE Field name new field name data type [ attribute ( Don't write )] ;
such , I will stu Inside the watch email Changed to mail, The data type is VARCHAR(50).
The way , I'm here
DataGripIt will be updated in time after operation , If you use other tools , You may have to refresh manually to respond !!!
Add fields
ALTER TABLE stu ADD demo VARCHAR(10) NOT NULL ;
-- ALTER TABLE Table name ADD The field name to add data type [ attribute ( Don't write )] ;
Delete field
ALTER TABLE stu DROP demo;
-- ALTER TABLE Table name DROP Field name ;
Add primary key constraint
-- ALTER TABLE Table name ADD CONSTRAINT Custom primary key name PRIMARY KEY Table name ( Field );
ALTER TABLE stu ADD CONSTRAINT PK_STU PRIMARY KEY stu(studentNo);
Primary key name , It can be named casually , But it's best to follow the rules ,
pk+ Underline + Table name , Such as :PK_STU`.
Add a foreign key constraint
-- ALTER TABLE Foreign key table name ADD CONSTRAINT Foreign key name FOREIGN KEY ( Foreign key field name ) REFERENCES Primary key table name ( Primary key field name );
ALTER TABLE result ADD CONSTRAINT FK_RESULT_STU FOREIGN KEY (studentNo) REFERENCES stu(studentNo);
Watch my watch , Primary key in
stuInside the watch , The foreign key table isresult, Don't get it wrong . The foreign key name specification isFK_ surface 1_ surface 2.
Little knowledge
We found that , We often use the above sentence ALTER TABLE This keyword .
We can check the help document with common sense .
If English is not good , Just search the browser honestly .
版权声明
本文为[JanYork_ Little Jane]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221017171240.html
边栏推荐
- 004-MYSQL的查询过程
- Slime 2022 展望:把 Istio 的复杂性塞入智能的黑盒
- Oracle 如何使用循环控制关键字exit、goto、continue
- 半个月东山再起,如果你哪天失业了,请务必收藏好5大自媒体工具
- Two ways to write Coriolis (understand 'fn.length' and 'FN. Tostring()')
- formDate保存数据
- 「译文」给讨厌YAML的人的10个写YAML的建议
- Idea writes sparksql program in local [*] mode, which can be run. Classnotfoundexception occurs when it is submitted to spark yarn for running
- Use of checkbox
- Formdate save data
猜你喜欢

003-MySQL索引

Linux Installation Oracle 19C Full Version (graphics + silent installation)

Error message during unity3d build: missing project ID in unity solution

数字化时代,企业运维面临现状及挑战分析解读

Three minute quick understanding of interactive graffiti

Challenges of enterprise web development
![[QT notes] use qpainter to draw various basic graphics](/img/7a/78e96d8689582d145586a4da3d3bb0.png)
[QT notes] use qpainter to draw various basic graphics

Interpretation of openeuler kernel technology | introduction to kernel interrupt subsystem

Oracle 如何使用循环控制关键字exit、goto、continue

Qt关于信号槽连接出现的一些问题记录
随机推荐
【设计必用!】网页设计常用色彩搭配表 《配色表》
Oracle account is locked. Unlocking method
*CTF 2022 Reverse Writeup
SPA首屏加载优化
vmware虚拟机下载并安装教程
Oracle帐户被锁了解锁方法
Film online ticket purchase system based on SSM
树形dp——P1122 最大子树和
[issue 307] in terms of implementation principle, why is Nacos so strong?
柯里化的两种写法(弄懂`fn.length`与`fn.toString()`)
项目如何解决跨域问题
JWT source code analysis (four layer package with schematic diagram)
formDate保存数据
Golang time formatting
Multi target tracking extended Kalman filter (EKF)
Google Earth Engine(GEE)——聚合网格化人口数据
Challenges of enterprise web development
西门子PLC能否通过以太网数据模块实现无线通讯?
Idea writes sparksql program in local [*] mode, which can be run. Classnotfoundexception occurs when it is submitted to spark yarn for running
Interpretation of openeuler kernel technology | introduction to kernel interrupt subsystem