当前位置:网站首页>Addition, deletion, modification and query of MySQL advanced table
Addition, deletion, modification and query of MySQL advanced table
2022-04-23 20:45:00 【Jan York】
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
DataGrip
It 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
stu
Inside 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 .
版权声明
本文为[Jan York]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204232039375755.html
边栏推荐
- The problem of 1 pixel border on the mobile terminal
- 3-5 obtaining cookies through XSS and the use of XSS background management system
- Learn to C language fourth day
- Queue template code
- 100天拿下11K,转岗测试的超全学习指南
- Three. Based on ply format point cloud voxel model JS upload interface writing
- Leetcode 1351. Negative numbers in statistical ordered matrices
- 一些接地气的话儿
- go slice
- MySQL数据库常识之储存引擎
猜你喜欢
MySQL基础合集
Cmake project under vs2019: calculating binocular parallax using elas method
UnhandledPromiseRejectionwarning:CastError: Cast to ObjectId failed for value
Actual measurement of automatic ticket grabbing script of barley network based on selenium (the first part of the new year)
41. 缺失的第一个正数
100天拿下11K,转岗测试的超全学习指南
How can matlab obtain the truncated image in trainingimagelabeler
Matlab: psychtoolbox installation
上海回应“面粉官网是非法网站”:疏于运维被“黑”,警方已立案
vulnhub DC:1渗透笔记
随机推荐
Thirty What are VM and VC?
一些接地气的话儿
vulnhub DC:1渗透笔记
软件测试要怎么学?自学还是培训看完这篇文章你就懂了
GO语言开发天天生鲜项目第三天 案例-新闻发布系统二
DOS command of Intranet penetration
Automatically fill in body temperature and win10 task plan
Recognition of high-speed road signs by Matlab using alexnet
Create vs project with MATLAB
Leetcode 709, convert to lowercase
go defer
MySQL stored procedures and functions
LeetCode 232、用栈实现队列
LeetCode 542、01 矩阵
Selenium displays webdriverwait
Devaxpress report replay: complete the drawing of conventional two-dimensional report + histogram + pie chart
Leetcode 232, queue with stack
go interface
Elastic box model
MySQL进阶之表的增删改查