- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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)
Advertisements
To Continue Learning Please Login
Login with Google