当前位置:网站首页>Default constraint and zero fill constraint of MySQL constraint
Default constraint and zero fill constraint of MySQL constraint
2022-07-07 21:13:00 【1024 questions】
Default constraint
Add default constraint
Delete default constraint
Zero fill constraint
summary
Default constraintMySQL The default value constraint is used to specify the default value of a column .
Add default constraintThe way 1: < Field name > < data class type > default < Default value >;
The way 2: alter table Table name modify Name class type default Default value ;
create table t_user10 (id int ,name varchar(20) ,address varchar(20) default ‘ Beijing ' -- Specify the default constraint );-- alter table Table name modify Name type default The default value is ;create table t_user11 (id int ,name varchar(20) ,address varchar(20));alter table t_user11 modify address varchar(20) default ‘ Beijing '; Delete default constraint -- alter table < Table name > modify column < Field name > < type > default null;alter table t_user11 modify column address varchar(20) default null; Zero fill constraint 1、 When inserting data , When the length of the value of this field is less than the defined length , This value will be preceded by the corresponding 0
2、zerofill The default is int(10)
3、 When using zerofill when , By default, it will automatically add unsigned( Unsigned ) attribute , Use unsigned After attribute , The numerical range is of the original value 2 times , for example , The sign is -128~+127, No sign is 0~256.
such as : Now set the length of a field to 5, So the real data is 1, So what appears in your database is 00001;
create table t_user12 (id int zerofill , -- Zero fill constraint name varchar(20));alter table t_user12 modify id int;-- 1. Adding constraints create table t_user12 (id int zerofill , -- Zero fill constraint name varchar(20));insert into t_user12 values(123, ' Zhang San ');insert into t_user12 values(1, ' Li Si ');insert into t_user12 values(2, ' Wang Wu ');
We learned a lot of constraints earlier , Here is a general summary , We need to set these constraints according to our own application scenarios , Finally, we can meet our daily needs :
-- summary -- 1: Add a primary key constraint by modifying the table structure create table emp4(eid int primary key,name varchar(20),deptId int,salary double);-- 2: Add a self increasing positive constraint create table t_user1 (id int primary key auto_increment,name varchar(20));-- 3: Create a non empty constraint create table mydb1.t_user6 (id int ,name varchar(20) not null, -- Specify a non NULL constraint address varchar(20) not null -- Specify a non NULL constraint );-- 4: Create a unique constraint create table t_user8 (id int ,name varchar(20) ,phone_number varchar(20) unique -- Specify a unique constraint );-- 5: Create default constraints create table t_user10 (id int ,name varchar(20) ,address varchar(20) default ' Beijing ' -- Specify the default constraint );This is about MySQL Default constraint of constraint default And zero fill constraints zerofill This is the end of the article , More about MySQL constraint Please search the previous articles of software development network or continue to browse the relevant articles below. I hope you will support software development network more in the future !
边栏推荐
- 浅解ARC中的 __bridge、__bridge_retained和__bridge_transfer
- 静态测试工具
- gridView自己定义做时间排版「建议收藏」
- FatMouse&#39; Trade(杭电1009)
- 程序猿赚的那点钱算个P啊!
- Mahout-Pearson correlation的实现
- 恶魔奶爸 B2 突破语法,完成正统口语练习
- 95年专注安全这一件事 沃尔沃未来聚焦智能驾驶与电气化领域安全
- H3C s7000/s7500e/10500 series post stack BFD detection configuration method
- Alibaba cloud award winning experience: how to mount NAS file system through ECS
猜你喜欢
Klocwork code static analysis tool

解决使用uni-app MediaError MediaError ErrorCode -5

Details of C language integer and floating-point data storage in memory (including details of original code, inverse code, complement, size end storage, etc.)

Make this crmeb single merchant wechat mall system popular, so easy to use!
![嵌入式系统真正安全了吗?[ OneSpin如何为开发团队全面解决IC完整性问题 ]](/img/af/61b384b1b6ba46aa1a6011f8a30085.png)
嵌入式系统真正安全了吗?[ OneSpin如何为开发团队全面解决IC完整性问题 ]

神兵利器——敏感文件发现工具

如何满足医疗设备对安全性和保密性的双重需求?
Codesonar enhances software reliability through innovative static analysis

Implement secondary index with Gaussian redis

ISO 26262 - 基于需求测试以外的考虑因素
随机推荐
恶魔奶爸 A1 语音听力初挑战
Intelligent transportation is full of vitality. What will happen in the future? [easy to understand]
AADL inspector fault tree safety analysis module
开户还得用身份证银行卡安全吗,我是小白不懂
私募基金在中國合法嗎?安全嗎?
Is it safe to open a stock account at present? Can I open an account online directly.
UVA 11080 – Place the Guards(二分图判定)
Deadlock conditions and preventive treatment [easy to understand]
Unity3d 4.3.4f1 execution project
C语言 整型 和 浮点型 数据在内存中存储详解(内含原码反码补码,大小端存储等详解)
解决使用uni-app MediaError MediaError ErrorCode -5
Validutil, "Rethinking the setting of semi supervised learning on graphs"
Is it safe to open an account online now? I want to know where I can open an account in Nanning now?
刚开户的能买什么股票呢?炒股账户安全吗
Micro service remote debug, nocalhost + rainbow micro service development second bullet
智能软件分析平台Embold
特征生成
使用高斯Redis实现二级索引
Details of C language integer and floating-point data storage in memory (including details of original code, inverse code, complement, size end storage, etc.)
Lingyun going to sea | yidiantianxia & Huawei cloud: promoting the globalization of Chinese e-commerce enterprise brands