找到 6705 篇文章 相关数据库
100 次浏览
这可以通过以下语句完成:mysql> select * from information_schema.triggers where -> information_schema.triggers.trigger_schema like '%query%'\G *************************** 1. row *************************** TRIGGER_CATALOG: def TRIGGER_SCHEMA: query TRIGGER_NAME: trigger_before_delete_sample EVENT_MANIPULATION: DELETE EVENT_OBJECT_CATALOG: def EVENT_OBJECT_SCHEMA: query EVENT_OBJECT_TABLE: sample ACTION_ORDER: 1 ACTION_CONDITION: NULL ACTION_STATEMENT: BEGIN SET @count ... 阅读更多
145 次浏览
这可以通过 INFORMATION_SCHEMA 数据库来完成。以下语句将提供触发器的元数据:mysql> Select trigger_schema, trigger_name, action_statement -> from information_schema.triggers\G *************************** 1. row *************************** trigger_schema: query trigger_name: trigger_before_delete_sample action_statement: BEGIN SET @count = if (@count IS NULL, 1, (@count+1)); INSERT INTO sample_rowaffected values (@count); END *************************** 2. row *************************** trigger_schema: query trigger_name: before_inser_studentage action_statement: IF NEW.age < 0 THEN SET NEW.age = 0; END IF *************************** 3. row *************************** trigger_schema: sys trigger_name: sys_config_insert_set_user action_statement: BEGIN IF @sys.ignore_sys_config_triggers != true AND NEW.set_by ... 阅读更多
179 次浏览
借助 SHOW TRIGGERS 语句,我们可以列出特定数据库中的所有触发器。这可以通过以下示例来说明:示例mysql> Show Triggers\G *************************** 1. row *************************** Trigger: trigger_before_delete_sample Event: DELETE Table: sample Statement: BEGIN SET @count = if (@count IS NULL, 1, (@count+1)); INSERT INTO sample_rowaffected values (@count); END Timing: BEFORE Created: 2017-11-21 12:31:58.70 sql_mode: ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERR OR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION Definer: root@localhost character_set_client: cp850 collation_connection: cp850_general_ci Database Collation: latin1_swedish_ci *************************** 2. ... 阅读更多
507 次浏览
我们可以通过使用“WITH ROLLUP”修饰符在 MySQL 结果集中获取列的摘要输出。此修饰符与 GROUP BY 子句一起使用。它提供的摘要输出包括表示更高级别汇总操作的额外行。示例在此示例中,“WITH ROLLUP”修饰符提供了带有总成本值的摘要输出,位于额外行中。mysql> Select Item_name, SUM(Cost) AS Total_cost from Item_list GROUP BY Item_name WITH ROLLUP; +-----------+------------+ | Item_name | Total_cost | +-----------+------------+ | Notebook | 45.00 | | Pen | 31.70 | | Pencilbox | 125.20 | | NULL | 201.90 | +-----------+------------+ 4 rows in set (0.00 sec)
4K+ 次浏览
我们必须了解使用 MySQL 触发器的优缺点和限制,以便我们可以有效地使用它。优点以下是使用 MySQL 触发器的优点:数据完整性 - 借助 MySQL 触发器,我们可以检查表中的数据完整性。换句话说,MySQL 触发器是检查数据完整性的另一种方法。用于捕获错误 - MySQL 触发器可以捕获数据库层中业务逻辑中的错误。运行计划任务的替代方法 - 实际上,通过使用 MySQL 触发器,我们不必等待运行计划任务,因为... 阅读更多
83 次浏览
借助以下 MySQL 语句,我们可以使用 SELECT 计算表达式:SELECT expression;上述语句没有引用任何表。以下是一些示例:mysql> Select 10 DIV 5; +----------+ | 10 DIV 5 | +----------+ | 2 | +----------+ 1 row in set (0.06 sec) mysql> Select 10*5; +------+ | 10*5 | +------+ | 50 | +------+ 1 row in set (0.00 sec) mysql> Set @var1 = 100, @var2 = 200; Query OK, 0 rows affected (0.00 sec) mysql> Select @Var1+@Var2; +-------------+ | @Var1+@Var2 | +-------------+ | 300 | +-------------+ 1 row in set (0.00 sec)
5K+ 次浏览
实际上,“FOR EACH ROW”表示对于每个匹配的行,这些行将被更新或删除。换句话说,我们可以说触发器不会应用于每一行,它只是说要为每个受影响的表行执行触发器体。我们可以通过以下示例来说明这一点:示例在此示例中,我们创建了两个表,Sample 和 Sample_rowaffected,如下所示:mysql> Create table Sample(id int, value varchar(20)); Query OK, 0 rows affected (0.47 sec) mysql> Insert into Sample(id, value) values(100, 'same'), (101, 'Different'), (500, 'excellent'), (501, 'temporary'); Query OK, 4 rows affected (0.04 sec) ... 阅读更多