当前位置:网站首页>Detailed explanation of alter field of MySQL Foundation
Detailed explanation of alter field of MySQL Foundation
2022-07-26 13:57:00 【1 2 3 pursue dreams together】
1、 First create a table testalter_tbl
create table testalter_tbl
(
i INT,
c CHAR(1)
);2、 Delete , Add or modify table fields
Delete field i
alter table testalter_tbl drop i
Be careful : If there is only one field left in the data table, it cannot be used DROP To delete fields .
Add fields i
Use ADD Clause to add columns... To the data table , The following examples are shown in table testalter_tbl Add i Field , And define data types :
ALTER TABLE testalter_tbl ADD i INT;
Be careful : After executing the above order ,i Fields are automatically added to the end of the data table fields .
You can also specify where to add fields , By using MySQL Keywords provided FIRST ( Set the first column ), AFTER Field name ( Set after a field ).
ALTER TABLE testalter_tbl DROP i;# Delete i This column ALTER TABLE testalter_tbl ADD i INT FIRST;# hold i This column is added to the first column
ALTER TABLE testalter_tbl DROP i;# Delete i This column ALTER TABLE testalter_tbl ADD i INT AFTER c;# hold i This column is added to c after
Be careful :FIRST and AFTER Keywords can be used for ADD And MODIFY Clause , So if you want to reset the location of data table fields, you need to use DROP Delete the field and use ADD To add fields and set the location .
3、 Modify field type and name
If you need to change the field type and name , You can ALTER Use in command MODIFY or CHANGE Clause .
Put field c Type from CHAR(1) Change it to CHAR(10)
ALTER TABLE testalter_tbl MODIFY c CHAR(10);
Use CHANGE Clause modification
ALTER TABLE testalter_tbl CHANGE i j BIGINT;# Can pass change Change the field name and field type
4、 ALTER TABLE Yes Null The effect of values and defaults
When you modify fields , You can specify whether to include values or whether to set default values .
ALTER TABLE testalter_tbl
MODIFY j BIGINT NOT NULL DEFAULT 100;Be careful : If you don't set the default value ,MySQL It will automatically set the default value of this field to NULL.
Modify the default
ALTER TABLE testalter_tbl ALTER i SET DEFAULT 1000;
Delete the default value of the field
ALTER TABLE testalter_tbl ALTER i DROP DEFAULT;
Modify the name of the table
ALTER TABLE testalter_tbl RENAME TO alter_tbl;
边栏推荐
- MySQL's practice of SQL analysis and optimization from the index principle
- Tdsql-c serverless: help start-ups achieve cost reduction and efficiency increase
- Go multithread communication, control coordination and main thread shutdown (sync.waitgroup)
- Share 44 JS problems, and half of them are masters
- 搞懂MySQL的数据类型中长度含义
- Zhou Wei: look for non consensual investment opportunities to accompany the founding team that delays satisfaction
- Docker swarm cluster builds highly available MySQL active and standby
- MySQL sets auto increment for existing primary keys
- Understand the meaning of length in MySQL data types
- Concept and handling of exceptions
猜你喜欢

估值15亿美元的独角兽被爆裁员,又一赛道遇冷?

重押海外:阿里、京东、顺丰再拼“内力”

Frisbee, 2022 "black red" top stream

Pytoch learning notes (I) installation and use of common functions

See you tomorrow at the industrial session of cloud intelligence technology forum!
![[oauth2] VII. Wechat oauth2 authorized login](/img/1a/3f2b9fc57759a1fa3fda1451492e5c.png)
[oauth2] VII. Wechat oauth2 authorized login

Circular queue (implemented in C language)

「中高级试题」:MVCC实现原理是什么?

12437 words, take you to explore the principle of RPC communication

C language_ Structure pointer variable introduction
随机推荐
Subscription and publication of messages
Time complexity and space complexity
白帽子揭秘:互联网千亿黑产吓退马斯克
Mobile dual finger scaling event (native), e.originalevent.touches
历时15年、拥有5亿用户的飞信,彻底死了
Thoughts on the compilation of Dr. Shuo's opening report
Rotation of 2D conversion, transform origin of 2D conversion center point and scale of 2D conversion
[shaders realize overlay to re cover cross dressing effect _shader effect Chapter 9]
Native JS get transform value x y z and rotate rotation angle
[paper reading] raw+:a two view graph propagation method with word coupling for readability assessment
Force deduction ----- the number of words in the string
技术分享 | 需要小心配置的 gtid_mode
Difference between base addressing and index addressing
Time complexity analysis of bubble sorting
JSON data returned by controller
Comparison between SIGMOD function and softmax function
MySQL's practice of SQL analysis and optimization from the index principle
万字长文,浅谈企业数字化建模蓝图
Inspiration from brain: introduction to synaptic integration principle in deep neural network optimization
POM file details