Help Creating an SQL Trigger Using Notepad - TechRepublic
Question
July 30, 2025 at 09:54 PM
ehidede

Help Creating an SQL Trigger Using Notepad

by ehidede . Updated 10 months, 1 week ago

Hi everyone,

I’m currently learning SQL and trying to create a trigger using Notepad for my MySQL database. I wrote the trigger script in Notepad and saved it as a .sql file. However, when I try to run it using the MySQL command line, I’m not sure if the syntax or formatting is correct.

Here’s what I’m trying to do: I want to automatically update a column in a table whenever a new row is inserted.

This is my sample trigger code:

DELIMITER //

CREATE TRIGGER update_timestamp
BEFORE INSERT ON employees
FOR EACH ROW
BEGIN
SET NEW.created_at = NOW();
END;
//

DELIMITER ;

When I run the file using this command:

bash
Copy
Edit
mysql -u root -p -D mydatabase < trigger_script.sql
I get an error, and I’m not sure if I’m missing something in Notepad formatting or syntax. Any advice or corrections would be appreciated!

Thanks in advance.
Dede

All Comments