当前位置:网站首页>mysql如何将字段修改为not null
mysql如何将字段修改为not null
2022-06-22 13:59:00 【亿速云】
mysql如何将字段修改为not null
本文小编为大家详细介绍“mysql如何将字段修改为not null”,内容详细,步骤清晰,细节处理妥当,希望这篇“mysql如何将字段修改为not null”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
在mysql中,可以通过使用ALTER TABLE语句给字段添加非空约束来将字段修改为not null,语法“ALTER TABLE 数据表名 CHANGE COLUMN 字段名 字段名 数据类型 NOT NULL;”。ALTER TABLE语句用于修改原有表的结构,而“NOT NULL”是设置非空约束的关键字;字段添加非空约束后,其值就不能为空,否则数据库系统就会报错。

本教程操作环境:windows7系统、mysql8版本、Dell G3电脑。
在mysql中,想要将字段修改为not null,可以给字段添加非空约束。
非空约束(NOT NULL)指字段的值不能为空。对于使用了非空约束的字段,如果用户在添加数据时没有指定值,数据库系统就会报错。
而给字段添加非空约束有两种语句:
CREATE TABLE 语句
ALTER TABLE 语句
但CREATE TABLE 语句是在创建表时设置,不符合要求;因此这里使用 ALTER TABLE 语句。语法:
ALTER TABLE 数据表名 CHANGE COLUMN 字段名字段名 数据类型 NOT NULL;
示例:将tb_students_score表中id字段修改为not null。
先看看表结构:
DESC tb_students_score;

给id字段添加非空约束
ALTER TABLE tb_students_scoreCHANGE COLUMN idid int(11) NOT NULL;

在看看表结构:

读到这里,这篇“mysql如何将字段修改为not null”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。
边栏推荐
- Fluentd is easy to get started. Combined with the rainbow plug-in market, log collection is faster
- Front and back management system of dessert beverage store based on SSM framework dessert mall cake store [source code + database]
- UE4 obtains local files through blueprints
- Fight, programmer chapter 43 kill one man in ten steps
- Closure of groovy
- I rely on the sideline to buy a house in full one year: the industry you despise will make a lot of money in the next ten years!
- flutter video_player实现监听和自动播放下一首歌曲
- Open source SPL redefines OLAP server
- New hybrid architecture iformer! Flexible migration of convolution and maximum pooling to transformer
- Flutter video Le lecteur écoute et joue automatiquement la prochaine chanson
猜你喜欢

PowerPoint 教程,如何在 PowerPoint 中添加水印?

Keil simulation and VSPD

Using virtual serial port to debug serial port in keil MDK

Specific methods and steps of PROFINET communication between s7-200smart and Fanuc robot

好风凭借力 – 使用Babelfish 加速迁移 SQL Server 的代码转换实践

得物技术复杂 C 端项目的重构实践

Driving the efficient growth of the manufacturing industry, UFIDA u9 cloud is constantly improving the password behind it

Software architecture
![[Software Engineering] design module](/img/08/d55af729a8241e109fdeb96c896670.png)
[Software Engineering] design module

Tree structured binary tree
随机推荐
Differences and performance of array, list, ArrayList, directory and LinkedList in C #
After 17 years, Liu Yifei became popular again: ordinary people don't want to be eliminated, but they also need to understand this
网站存在的价值是什么?为什么要搭建独立站
C # paging calculation total pages, current page data set
What is the value of a website? Why build an independent station
Phpstudy 2016 build Pikachu range
Flutter video Le lecteur écoute et joue automatiquement la prochaine chanson
Live broadcast goes to sea | domestic live broadcast room produces explosive products again. How can "roll out" win the world
MySQL learning notes 2022
得物技术复杂 C 端项目的重构实践
U++ 运营商 学习笔记
Error: unable to find a match: lrzsz
Countdown to the conference - Amazon cloud technology innovation conference invites you to build a new AI engine!
Go all out to implement the flood control and disaster relief measures in detail and in place, and resolutely protect the safety of people's lives and property
Database connection pool: stress testing
我靠副业一年全款买房:那个你看不起的行业,未来十年很赚钱!
[Zhejiang University] information sharing of the first and second postgraduate entrance examinations
Vscode个性化设置:让一个小萌妹陪你敲代码
Deadlock found when trying to get lock; Try restarting transaction
Recommendation of individual visa free payment scheme