当前位置:网站首页>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
边栏推荐
猜你喜欢
一些接地气的话儿
Another data analysis artifact: Polaris is really powerful
Plato farm is one of the four largest online IEOS in metauniverse, and the transaction on the chain is quite high
The construction and use of Fortress machine and springboard machine jumpserver are detailed in pictures and texts
又一款数据分析神器:Polars 真的很强大
[stack and queue topics] - sliding window
浅谈数据库设计之三大范式
Recommended usage scenarios and production tools for common 60 types of charts
常用60类图表使用场景、制作工具推荐
Unity animation creates sequence frame code and generates animationclip
随机推荐
SQL gets the latest record of the data table
三十.什么是vm和vc?
Go language development Daily Fresh Project Day 3 Case - Press Release System II
又一款数据分析神器:Polars 真的很强大
Preliminary understanding of cache elimination algorithm (LRU and LFU)
Unity asset import settings
BMP JPEG picture to vector image contourtrace
C migration project record: modify namespace and folder name
Recognition of high-speed road signs by Matlab using alexnet
laravel 发送邮件
Awk print special characters
The problem of 1 pixel border on the mobile terminal
Send email to laravel
"Meta function" of tidb 6.0: what is placement rules in SQL?
[PTA] get rid of singles
[stack and queue topics] - sliding window
go defer
go interface
Pikachuxss how to get cookie shooting range, always fail to return to the home page
go slice