首页 > 数据库 >mysql set column sha2(uuid(),512) as column default value via trigger

mysql set column sha2(uuid(),512) as column default value via trigger

时间:2023-12-09 23:14:31浏览次数:48  
标签:sha2 11 26 set column create t3 19 24

mysql> show create table t3;
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                   |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t3    | CREATE TABLE `t3` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `topic` varchar(255) NOT NULL COMMENT 'book topic',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> desc t3;
+-------------+-----------------+------+-----+-------------------+-------------------+
| Field       | Type            | Null | Key | Default           | Extra             |
+-------------+-----------------+------+-----+-------------------+-------------------+
| id          | bigint unsigned | NO   | PRI | NULL              | auto_increment    |
| create_time | datetime        | NO   |     | CURRENT_TIMESTAMP | DEFAULT_GENERATED |
| topic       | varchar(255)    | NO   |     | NULL              |                   |
+-------------+-----------------+------+-----+-------------------+-------------------+
3 rows in set (0.00 sec)

mysql> create trigger before_insert_t3 before insert on t3 for each row set new.topic=sha2(uuid(),512);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t3(id,create_time) select id,create_time from t2 limit 10;
Query OK, 10 rows affected (0.00 sec)
Records: 10  Duplicates: 0  Warnings: 0

mysql> select * from t3;
+----+---------------------+----------------------------------------------------------------------------------------------------------------------------------+
| id | create_time         | topic                                                                                                                            |
+----+---------------------+----------------------------------------------------------------------------------------------------------------------------------+
|  1 | 2023-11-26 19:24:11 | c9591be56a93269d01ce265b7c26955a3a8c0b30c82c89ae2239f578ee3c797a370761d2cba5d02ce25033f35bd572aae093b34cf63ef7b1e7d3634cc3e59742 |
|  2 | 2023-11-26 19:24:11 | 2fcf18fc7ac4800ddc563b6838a3cb4cbc008e6763c6747d168031347283a27701260ea51be87f69010b80a1d1088dba78fe2e5c10d2e8526de03f5bd6f89ab1 |
|  3 | 2023-11-26 19:24:11 | d439f56c9ed522edaa10a5d10424c05d5b6cdc69568bb0d7f186c40e9c96be740e2d04f714e3fee0d4572bef9147b3bb7e49ec1ca3f7f637668be54ece0fc191 |
|  4 | 2023-11-26 19:24:11 | 85f318a17ce27e03aab0a2d5528f5fc38c866d5ba8ae6755d6ae870b92bdb1d2dc538c7eafe465296c651198c0ae3f6d79d247297bd7e600bd77d9dc7af92e7e |
|  5 | 2023-11-26 19:24:11 | 36757664c3128342397116bd8c9502c3dd073b85926107d1e749efeceea91836a4c22557af02c7d6c542f1a9bfc4cf3f653dc1c32a949556b18b58d870908e54 |
|  6 | 2023-11-26 19:24:11 | f1cf90b0da198d8f840291605d24b65ec8f8e7d6431631f82a4341c9e593e69762be4d9bf8c8bc9203feae8e3294dc6a3ea5725d0a4afc8adbdb4343bacddaaa |
|  7 | 2023-11-26 19:24:11 | d8d1cc98d62209dc94a05ebc4be377b084189191e49270322bc9e685043f01221c18c8b502fbc54c55a83a0dd2df21c55cadeceb87749080ec7830e295a57f32 |
|  8 | 2023-11-26 19:24:11 | 43bfa6d5dce261f72d1f9679304ff6f1a3d6bfc9002cc0ad58b3cce4df7f0c013dd889070b081ffda118979263f6825f0450b2f9b8fa460b7d6dfadb475f7448 |
|  9 | 2023-11-26 19:24:11 | a3fcf8ce4a816a79a3e3902c3456aa5f198bc4a3709f03c25c0bb3ff3484aff08510b0674b15beb6a532e9fe9024b8b31ff00ca10ccdbd51bfc4f06f1afe9065 |
| 10 | 2023-11-26 19:24:11 | 552900c24b66f841d87782b72d4d183c43fd8be0fb00bc7990de877f3755460d29fd4cd6001d069d0162770978bd55e4e07b7db615516f965f9c616ce7d80176 |
+----+---------------------+----------------------------------------------------------------------------------------------------------------------------------+
10 rows in set (0.00 sec)

mysql> 

 

 

//create before trigger 

create trigger before_insert_t3 before insert on t3 for each row set new.topic=sha2(uuid(),512);
insert into t3(id,create_time) select id,create_time from t2 limit 10;

 

 

 

标签:sha2,11,26,set,column,create,t3,19,24
From: https://www.cnblogs.com/Fred1987/p/17891974.html

相关文章

  • CPUSETS 【ChatGPT】
    https://www.kernel.org/doc/html/v6.6/admin-guide/cgroup-v1/cpusets.htmlCPUSETS1.Cpusets1.1什么是cpusets?Cpusets提供了一种机制,用于将一组CPU和内存节点分配给一组任务。在本文档中,“内存节点”指的是包含内存的在线节点。Cpusets限制了任务的CPU和内存放置......
  • DataTables中的column().visible()
    DataTables中的column().visible()用来获取/设置单个选定列的可见性。描述在数据表中显示和隐藏列非常方便,尤其是在显示信息密度较大的表时。此方法允许即时更改单个列的可见性,或读取列的可见性状态。函数column().visible()描述:获取所选列的可见性。返回值:booleantrue如果该......
  • 【JavaSE】集合Collection{List(ArrayList, LinkedList), Set(TreeSet, HashSet, Link
    集合单列集合:Collection接口单列集合:一次添加一个元素;如果集合中添加的是类,要重写equals方法,否则比较的是地址,无法正常删除内容相同的元素。单列集合通用遍历方式1.迭代器遍历2.增强for循环遍历增强for循环底层逻辑还是迭代器,字节码文件反编译为java会发现还是迭代......
  • 【JavaSE】数据结构-哈希表(HashSet/HashMap底层哈希表详解,源码分析)
    哈希表结构JDK8版本之前:数组+链表JDK8版本及之后:数组+链表+红黑树哈希表HashMapput()方法的添加流程创建HashSet集合时,构造方法中自动创建HashMap集合;HashMap空参构造方法会创建一个默认长度为16,默认加载因子为0.75的数组,数组名为table(tips:实际上,HashSet对象创建后,第......
  • maven 配置(cmd 黑窗口执行 mvn 时默认的 settings 文件和 idea maven 相关配置)
    写在前面:本文章用于记录博主平时遇到的问题,步骤略粗糙,目的在于记录一边后续博主自己查找,如果能帮助到其他人更好。文章中用到的链接均为自行引入,侵删,谢谢(2I2Rc*@JY8)问题说明:在一次使用cmdmvn命令通过下载到本地的第三方jar包(ojdbc8.jar)创建本地maven仓库的文件结构时发现......
  • Solution Set #3
    紧急更新。上OI-transit上加训构造,感觉OI-transit是很好的找题网站。25loj6736. 「2020集训队论文」最小连通块应该加个部分分:DFS序是\(1\simn\)。你考虑这个部分分怎么做。一种做法是剥叶子,每次找到一个叶子的父亲。存在判断一个点是否是另一个点祖先的方法:询问\(......
  • 【SQLServer2019备份恢复】查询本身有问题、未正确设置 "ResultSet" 属性、未正确设置
    在SQLServer2019AlwaysOn节点备份策略失败:备份数据库(完整)(8502-HIS-SQLAG\HISAG)备份数据库所在的位置:本地服务器连接兼容性级别为70(SQLServer7.0版)的数据库将被跳过。数据库:所有用户数据库类型:完整追加现有任务开始:2023-12-08T14:10:07。任务结束:20......
  • nerdctl run -d 报"failed to call cni.Setup: plugin type=\"bridge\" failed (ad
    背景:执行 nerdctl run-d --namenginx-p8080:80nginx时,报如下错误FATA[0000]failedtocreateshimtask:OCIruntimecreatefailed:runccreatefailed:unabletostartcontainerprocess:errorduringcontainerinit:errorrunninghook#0:errorrunningh......
  • ComplexUpset包画upset图
    需要的数据格式:其中1、0用于表示该类别是否存在这类数据,也可以用TRUE跟FALSE来代替  upset(data_use,unique(colnames(data_use)),name="genres",#底部的标签width_ratio=0.01,#左侧图形的宽度mode='inclusive_intersection', #该包提供四种模......
  • 当创建statefulset资源后,k8s组件如何协作
    本文分享自华为云社区《当创建StatefulSet后,k8s会发生什么?》,作者:可以交个朋友。一、StatefulSet介绍StatefulSet是用来管理有状态应用的工作负载对象,StatefulSet管理基于相同容器规约的一组Pod,使用持久标识符为工作负载Pod提供持久存储。和Deployment类似,也属于副本控制器,......