实现"mysql 查看对表的操作记录"

整体流程

首先,我们需要创建一个表来记录对其他表的操作记录。然后,通过触发器来实现对操作记录的插入。最后,我们可以查询这个记录表来查看对表的操作记录。

```mermaid
erDiagram
    Table ||--|| OperationRecord : has
```mermaid
stateDiagram
    Table --> ViewRecord

详细步骤

  1. 创建操作记录表OperationRecord
CREATE TABLE OperationRecord (
    id INT PRIMARY KEY AUTO_INCREMENT,
    table_name VARCHAR(50),
    operation_type VARCHAR(10),
    operation_time TIMESTAMP
);
  1. 创建一个触发器,在对表进行增加、删除、更新操作时,插入记录到OperationRecord表中
DELIMITER //
CREATE TRIGGER tr_record_operation
AFTER INSERT ON Table
FOR EACH ROW
BEGIN
    INSERT INTO OperationRecord (table_name, operation_type, operation_time)
    VALUES ('Table', 'INSERT', NOW());
END;
//
DELIMITER ;

DELIMITER //
CREATE TRIGGER tr_record_operation
AFTER DELETE ON Table
FOR EACH ROW
BEGIN
    INSERT INTO OperationRecord (table_name, operation_type, operation_time)
    VALUES ('Table', 'DELETE', NOW());
END;
//
DELIMITER ;

DELIMITER //
CREATE TRIGGER tr_record_operation
AFTER UPDATE ON Table
FOR EACH ROW
BEGIN
    INSERT INTO OperationRecord (table_name, operation_type, operation_time)
    VALUES ('Table', 'UPDATE', NOW());
END;
//
DELIMITER ;

3. 查询操作记录表OperationRecord,查看对Table的操作记录

```sql
SELECT * FROM OperationRecord WHERE table_name = 'Table';

通过以上步骤,你可以实现"mysql 查看对表的操作记录"的功能。希望这篇文章能帮助到你,加油!