当前位置:网站首页>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
边栏推荐
- Go限制深度遍历目录下文件
- Bash script learning -- for loop traversal
- Send email to laravel
- Scripy tutorial - (2) write a simple crawler
- Install MySQL 5.0 under Linux 64bit 6 - the root password cannot be modified
- 电脑越用越慢怎么办?文件误删除恢复方法
- 三十.什么是vm和vc?
- Automatically fill in body temperature and win10 task plan
- 內網滲透之DOS命令
- 居家第二十三天的午饭
猜你喜欢

Unity Odin ProgressBar add value column

Resolve the error - error identifier 'attr_ id‘ is not in camel case camelcase

BMP JPEG picture to vector image contourtrace

常用60类图表使用场景、制作工具推荐

The construction and use of Fortress machine and springboard machine jumpserver are detailed in pictures and texts

Imitation Baidu map realizes the three buttons to switch the map mode by automatically shrinking the bottom

MySQL进阶之表的增删改查

Cmake project under vs2019: calculating binocular parallax using elas method

LeetCode 116. 填充每个节点的下一个右侧节点指针

上海回应“面粉官网是非法网站”:疏于运维被“黑”,警方已立案
随机推荐
Resolve the eslint warning -- ignore the warning that there is no space between the method name and ()
Elastic box model
Learn to C language fourth day
LeetCode-279-完全平方数
go interface
Recognition of high-speed road signs by Matlab using alexnet
上海回应“面粉官网是非法网站”:疏于运维被“黑”,警方已立案
go reflect
Resolve the error - error identifier 'attr_ id‘ is not in camel case camelcase
The iswow64process function determines the number of program bits
MySQL进阶之数据的增删改查(DML)
MySQL stored procedures and functions
LeetCode 1351、统计有序矩阵中的负数
Matlab matrix index problem
Matlab: psychtoolbox installation
Selenium 显示等待WebDriverWait
I JS deep copy and shallow copy
软件测试要怎么学?自学还是培训看完这篇文章你就懂了
Learn to C language fourth day
深入探究ASP.NET Core读取Request.Body的正确方式