- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What to assign to a MySQL column that must not be empty?
Define with NOT NULL, if a column must not be empty. Let us first create a table with one of the columns as NOT NULL −
mysql> create table DemoTable1895 ( Id int NOT NULL, FirstName varchar(20), LastName varchar(20) NOT NULL ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1895 values(100,'John','Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1895 values(NULL,'Chris','Brown'); ERROR 1048 (23000): Column 'Id' cannot be null mysql> insert into DemoTable1895 values(102,'Carol',NULL); ERROR 1048 (23000): Column 'LastName' cannot be null mysql> insert into DemoTable1895 values(103,NULL,'Miller'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1895;
This will produce the following output −
+-----+-----------+----------+ | Id | FirstName | LastName | +-----+-----------+----------+ | 100 | John | Smith | | 103 | NULL | Miller | +-----+-----------+----------+ 2 rows in set (0.00 sec)
- Related Articles
- Empty string in not-null column in MySQL?
- MySQL query to get a field value that does not contain empty spaces?
- MySQL query to update a specific cell to be empty
- Create a column on my table that allows null but is set by default to empty (not null)?
- Alter a MySQL column to be AUTO_INCREMENT?
- In MySQL, how it can be possible to specify a sort order using a column that is not retrieved by the query?
- MySQL query to check if database is empty or not?
- Change a MySQL column to have NOT NULL constraint
- How to add a NOT NULL column in MySQL?
- How it is possible to insert a zero or an empty string into a MySQL column which is defined as NOT NULL?
- How should I store data into my Mysql database, what type should I assign to a column storing salt values?
- How to select row when column must satisfy multiple value in MySQL?
- What happens if I will assign a value to a MySQL user variable using a statement that returns multiple rows?
- How to assign values to an array with null/empty objects in JavaScript?
- On inserting ‘NULL’, ‘0’ or No Value to the column, will MySQL assign sequence number for AUTO_INCREMENT column?

Advertisements