2

I want to insert informations from carti into domeniu but i get an error message.

CREATE TRIGGER trigger_UpdateItemDetails ON carti
FOR INSERT AS
BEGIN

INSERT INTO 
domeniu
(
    cod_d,
    materia,
    result
)
SELECT 
    id
    domeniu
    nr_exemplare
FROM 
   carti
END

The error message: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ON result FOR INSERT AS BEGIN INSERT INTO domeniu ( ' at line 1

1
  • Post the error message as well. Commented Jan 9, 2016 at 17:53

2 Answers 2

1

Problem is FOR INSERT AS. It should BEFORE INSERT AS. Check MySQL Documentation for CREATE TRIGGER syntax. Looks like you mixed up SQL Serer syntax. For Trigger is MSSQL syntax.

CREATE
    [DEFINER = { user | CURRENT_USER }]
    TRIGGER trigger_name
    trigger_time trigger_event
    ON tbl_name FOR EACH ROW
    [trigger_order]
    trigger_body

trigger_time: { BEFORE | AFTER }

trigger_event: { INSERT | UPDATE | DELETE }
Sign up to request clarification or add additional context in comments.

Comments

0

You should name the triggers using the following naming convention:

(BEFORE | AFTER)_tableName_(INSERT| UPDATE | DELETE)

for example after_tableName_insert

Refer below tutorial for creating triggers. http://www.mysqltutorial.org/mysql-trigger-implementation.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.