- Trending Categories
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
How to set MySQL default value NONE?
To set the default value in MySQL, you need to use the DEFAULT keyword. Let us first create a table −
mysql> create table DemoTable ( ClientCountryName varchar(100) DEFAULT 'NONE' ); Query OK, 0 rows affected (0.65 sec)
We have set DEFAULT above for values not entered while insertion. Now, let us insert some records in the table using the insert command. We haven’t inserted values here for some of the rows. The DEFAULT gets set there −
mysql> insert into DemoTable values('US'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('UK'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('AUS'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------------+ | ClientCountryName | +-------------------+ | US | | NONE | | UK | | NONE | | AUS | +-------------------+ 5 rows in set (0.00 sec)
Advertisements