MS Access - Syntax error on CREATE TABLE Statement in MySql - using Trigger - ms-access

For some reason, i can't get this to work..
CREATE TRIGGER triggerupdate
INSTEAD OF UPDATE ON ORDERDETAILS
AS
IF UPDATE(ORDERVALUE) BEGIN
Print ('INSTEAD OF Trigger [triggerupdate] - Trigger executed!!')
Print('You cannot update Order Value')
END
I'm trying to do a trigger if someone tries to update OrderValue. IT kept saying that Syntax error on Create Table.
Let me know what I have wrong.
Thanks

You can't use MS Access. Access does not support TRIGGERs, that's why you're getting Syntax errors, because "CREATE TRIGGER" is not supported SQL in Access.
Also, Print isn't a function in Access SQL either.
It's possible that you're meant to use Access as a front-end for MSSQL Server, which can be done, and where your SQL statements will become valid (but your use of Print is archaic).

Related

My SQL Syntax error for multiple commands in one query, working for each command running separately

I'm trying to run the following MySQL command:
USE database_name;
DROP TEMPORARY TABLE IF EXISTS only_with_balance;
DROP TEMPORARY TABLE IF EXISTS keys_to_match;
CREATE TEMPORARY TABLE only_with_balance as (
SELECT
*
FROM
transactions t
WHERE
t.balance is not NULL
and (t.transaction_status_id = 4 or t.transaction_status_id = 5)
and (t.date between "2022-05-01" and "2022-08-24" )
);
But I'm getting a syntax error while trying to run the all the commands at once.
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 'DROP TEMPORARY TABLE IF EXISTS only_with_balance;
DROP TEMPORARY TABLE IF EXIST' at line 2
When I run each command separately, the result is the expected.
Can someone help me here?
What am I forgetting?
In MySQL, by default the query interface only allows one SQL statement per call.
There's an option to enable multi-query per call, but it must be set at connect time. Some MySQL connectors do this by default, or allow it as an option, but some do not. You didn't say if you're writing code or if you're submitting this set of queries through a client (though you tag the question 'dbeaver' you don't say anything else about that). So I can't guess what interface you're using for these queries.
Anyway, there's no advantage to using multi-query. The default mode is one SQL statement per call. That's what I do.
Using the default mode of a single SQL statement per call has some advantages:
Supports prepared statements and bound parameters (you can't run multiple statements in a single prepare call, even if you enable multi-query).
Simplifies processing errors and warnings.
Simplifies processing result sets.

Trigger not creating in mySQL

I am trying to write a trigger for my database in mySQL yet when I run the query and then run SHOW TRIGGERS nothing is showing. I believe my syntax is correct and am not running into any errors when running the query. The query is below, any ideas why this is happening?
CREATE TRIGGER after_violation_insert
AFTER INSERT
ON violation
FOR EACH ROW
UPDATE listing
SET Listing_True_False = "true"
WHERE Listing_ID = new.Listing_ID;

SQL Trigger on database to restrict drop/alter/create syntax error, despite following tutorial, ON is not valid at this position?

Working on a security DDL trigger for a database and want to restrict non-admins from creating/dropping database, I have created this trigger and put it below all the other code (create tables etc) in the database script.
CREATE TRIGGER alert_table
ON DATABASE
FOR CREATE_TABLE, DROP_TABLE, ALTER_TABLE
AS
BEGIN
IF IS_MEMBER ('admin') = 0
BEGIN
PRINT 'Please contact your Database Admin'
ROLLBACK TRANSACTION;
END
END
GO
CREATE
Note:
USER 'admin'#'localhost'
It says "ON is not valid at that position, expecting: BEFORE or AFTER", and something similar for "END". Thanks!
You followed a tutorial for Microsoft SQL Server, commonly abbreviated as mssql server, while you are using mysql.
Mssql server has DDL triggers which syntax follows the one in your question.
Mysql's create trigger syntax is different and does not have DDL triggers at all, so you cannot use triggers to handle table creation events.

MySQL Workbench "OLD" syntax changed?

I had a trigger set in MySQL workbench that used to accomplish what I wanted. Recently, my workplace updated MySQL workbench to version 6.3.10 across all computers and the triggers were dropped during the update for some reason.
Basically, the trigger should update a column with the current date when a different column is changed. This was previously achieved by using the following syntax:
if (NEW.colname <> OLD.colname or (OLD.colname is null && NEW.colname is not null))
then
set NEW.othercolname = current_date()
The issue is when I try to recreate the same trigger in the new MySQL version and apply it, I am met with the error:
ERROR 1363: There is no OLD row in on INSERT trigger
It seems to me that MySQL is looking for a row named OLD, which does not exist; however, this syntax used to work in previous versions for the intended result. Can anyone suggest an alternative syntax to accomplish this?
First of all, the error message comes from mysql, not from mysql workbench, so mysql workbench's version is irrelevant here.
Secondly, the error message is pretty clear: you are trying to refer to the OLD row in an insert trigger. This is obviously impossible, since there is no old row when you insert a new one.
You need to change either the trigger to catch an update event or change the trigger logic.
ERROR 1363: There is no OLD row in on INSERT trigger
You've got MySQL Workbench set to create an INSERT trigger. As the error message says, there's no OLD row in an INSERT trigger.
What you want is an UPDATE trigger.

error 1064 in trigger mysql

This is my first time using mysql and I am tying to learn how to use trigger.
Im using navicat, i go to table design and then go triggers tab. I create a trigger named testing and in definition I typed:
delimiter |
CREATE TRIGGER lpr.mytesting AFTER INSERT ON lpr.lpr_opt_upload
FOR EACH ROW BEGIN
set new.lpr_text := reverse(new.lpr_text);
END;
| delimiter ;
All im tying to do is whenever something new is inserted, I reverse the text in lpr_text field. However, i get "1064 - you have an error in your SQL; check the manual that corresponds o your MySql server version for the right syntax to yse 'ON lpr_opt_upload' FOR EACH ROW create trigger testing before insert on lpr_op' at line 1." I dont understand what Im doing wrong, I am just copying an trigger example.
//-------------------------------------------------------------------------//
I figured out the problem. I am using navicat and in navicat trigger tab, you only type the body into the definition, Not the header (ex: CREATE TRIGGER lpr.mytesting AFTER INSERT ON lpr.lpr_opt_upload). There are check box next to the name of your trigger and you use those instead of writing your own header.
The DELIMITER command is a client command, which not all clients support (it doesn't get sent to the server at all, it just instructs the client how to tell statements apart in order that they get sent to the server correctly). References to it in the MySQL manual assume that you are using the 'official' MySQL clients, such as the mysql command-line tool or MySQL Workbench (both of which support the DELIMITER command).
I don't know how to change the statement delimiter in Navicat, but that is the root of your problem.