 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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 use a function for default value in MySQL?
We cannot use a function for default value in MySQL, but we can use triggers. Let us see an example.
First, we will create a table. The CREATE command is used to create a table.
mysql> CREATE table TbLFunctionTrigger - > ( - > id int, - > username varchar(100) - > ); Query OK, 0 rows affected (0.55 sec)
The following is the syntax to create a trigger and include a default value.
CREATE TRIGGER anyName BEFORE INSERT ON yourTableName FOR EACH ROW SET new.columnname = uuid();
Let us now implement a query to create a trigger.
mysql> CREATE TRIGGER insertBef - > BEFORE INSERT ON TbLFunctionTrigger - > FOR EACH ROW - > SET new.id = uuid(); Query OK, 0 rows affected (0.14 sec)
The above query sets a default value.
Advertisements
 