Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
