当前位置:网站首页>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
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 .
版权声明
本文为[Jan York]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204232039375755.html
边栏推荐
- 居家第二十三天的午饭
- The iswow64process function determines the number of program bits
- Unity asset import settings
- Recommended usage scenarios and production tools for common 60 types of charts
- GO语言开发天天生鲜项目第三天 案例-新闻发布系统二
- bounding box iou
- How to do after winning the new debt? Is it safe to open an account online
- Async function ------ ES6
- Selenium 显示等待WebDriverWait
- Leetcode 1351. Negative numbers in statistical ordered matrices
猜你喜欢

C migration project record: modify namespace and folder name

BMP JPEG picture to vector image contourtrace

【栈和队列专题】—— 滑动窗口

100天拿下11K,转岗测试的超全学习指南
![[PTA] get rid of singles](/img/ab/b5d49f336cbfbede23b3377a9314ad.png)
[PTA] get rid of singles

2021-09-02 unity project uses rider to build hot change project failure record of ilruntime

JS arrow function user and processing method of converting arrow function into ordinary function

Actual measurement of automatic ticket grabbing script of barley network based on selenium (the first part of the new year)

High paid programmer & interview question series 91 limit 20000 loading is very slow. How to solve it? How to locate slow SQL?

GO語言開發天天生鮮項目第三天 案例-新聞發布系統二
随机推荐
Commande dos pour la pénétration de l'Intranet
Recognition of high-speed road signs by Matlab using alexnet
JS arrow function user and processing method of converting arrow function into ordinary function
Leetcode 709, convert to lowercase
go reflect
Resolve the error - error identifier 'attr_ id‘ is not in camel case camelcase
Bash script learning -- for loop traversal
Leetcode 232, queue with stack
[stack and queue topics] - sliding window
UKFslam
Learn to C language fourth day
Go限制深度遍历目录下文件
LeetCode 1346、检查整数及其两倍数是否存在
内网渗透之DOS命令
How to learn software testing? Self study or training? After reading this article, you will understand
MySQL进阶之表的增删改查
Go limit depth traversal of files in directory
6-5 string - 2 String copy (assignment) (10 points) the C language standard function library includes the strcpy function for string copy (assignment). As an exercise, we write a function with the sam
"Meta function" of tidb 6.0: what is placement rules in SQL?
Shanghai responded that "flour official website is an illegal website": neglect of operation and maintenance has been "hacked", and the police have filed a case