# How to use trigger in order to insert a new row into the same table?

**URL:** <https://forum.codewithmosh.com/t/how-to-use-trigger-in-order-to-insert-a-new-row-into-the-same-table/7629>\
**Category:** SQL\
**Created:** [September 29, 2021, 7:45am UTC](https://forum.codewithmosh.com/t/how-to-use-trigger-in-order-to-insert-a-new-row-into-the-same-table/7629 "2021-09-29T07:45:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GM\_sql](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@GM\_sql](https://forum.codewithmosh.com/u/GM_sql)\
**Post date:** [September 29, 2021, 7:45am UTC](https://forum.codewithmosh.com/t/how-to-use-trigger-in-order-to-insert-a-new-row-into-the-same-table/7629/1 "2021-09-29T07:45:35Z")

</div>

Hi, I know that this might be challenging but I’d like to use the same table. Any ideas how to hack it?

```auto
DELIMITER $$
CREATE TRIGGER slug_after_insert
    AFTER INSERT ON pb_trig
    FOR EACH ROW
BEGIN
    IF NEW.element_id = 1 THEN
        SET @txt = NEW.content;
        SET @txt = txt2slug(@txt);
        INSERT INTO pb_trig(post_id, element_id, lang_id, slug)
        VALUES (NEW.post_id, 3, NEW.lang_id, @txt);
    END IF;
END $$
DELIMITER ;

```

---

<div class="post-metadata">

**Author:** ![kavfam](https://avatars.discourse-cdn.com/v4/letter/k/a87d85/32.png) [@kavfam](https://forum.codewithmosh.com/u/kavfam)\
**Post date:** [October 29, 2021, 1:01am UTC](https://forum.codewithmosh.com/t/how-to-use-trigger-in-order-to-insert-a-new-row-into-the-same-table/7629/2 "2021-10-29T01:01:02Z")

</div>

Thats mission impossible to avoid infinite triggers. Take a look at this - might be an option? [mysql - Create Trigger that updates the same table before (or after ??) the Insert - Database Administrators Stack Exchange](https://dba.stackexchange.com/questions/234779/create-trigger-that-updates-the-same-table-before-or-after-the-insert)
