| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

07-03-11, 22:06
|
|
Registered User
|
|
Join Date: Jul 2011
Posts: 3
|
|
Error in create trigger in mysql
|
|
I have create a trigger in SQL server, the code can function well
but when i paste the same code in MySql, It found that got lots of errors,
but i do not know what the error, why cant create successful
the code show below, can anyone help me
Code:
CREATE TRIGGER New_User
ON tblAdmin
AFTER INSERT
AS
DECLARE
@AdminRECID uniqueidentifier,
@CreateUser varchar(50),
@CreateDate datetime,
@AuditUser varchar(50),
@AuditDate datetime,
@MenuRECID uniqueidentifier
BEGIN
SELECT RECID = @AdminRECID,
CreateUser = @CreateUser,
CreateDate = @CreateDate,
AuditUser = @AuditUser,
AuditDate = @AuditDate
FROM tblAdmin;
SELECT RECID = @MenuRECID
FROM tblMenu;
INSERT INTO tblAdmin_Access(RECID,AdminRECID,MenuRECID,Status,CreateUser,CreateDate,AuditUser,AuditDate)
VALUES ((newid()),@AdminRECID,@MenuRECID,'A',@CreateUser,@CreateDate,@AuditUser,@AuditDate);
END;
|
|

07-03-11, 22:17
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
Quote:
Originally Posted by ying7690
but when i paste the same code in MySql, It found that got lots of errors
|
that's because mysql's trigger syntax is very different from sql server's trigger syntax
you basically have to re-write it
|
|

07-03-11, 22:19
|
|
Registered User
|
|
Join Date: Jul 2011
Posts: 3
|
|
|
|
Quote:
Originally Posted by r937
that's because mysql's trigger syntax is very different from sql server's trigger syntax
you basically have to re-write it
|
do you have any sample can let me reference, because i got try several time for it, it still cannot work appropriate
|
|

07-03-11, 22:58
|
|
Registered User
|
|
Join Date: Jul 2011
Posts: 3
|
|
Error Code: 1415. Not allowed to return a result set from a trigger"
I have the following code for trigger
the syntax message was
"Error Code: 1415. Not allowed to return a result set from a trigger"
Code:
delimiter $$
CREATE TRIGGER New_User AFTER INSERT ON tblAdmin
FOR EACH ROW
BEGIN
DECLARE _AdminRECID char(36);
DECLARE _CreateUser varchar(50);
DECLARE _CreateDate datetime;
DECLARE _AuditUser varchar(50);
DECLARE _AuditDate datetime;
DECLARE _MenuRECID CHAR(36);
SELECT RECID = _AdminRECID,
CreateUser = _CreateUser,
CreateDate = _CreateDate,
AuditUser = _AuditUser,
AuditDate = _AuditDate
FROM tblAdmin;
SELECT RECID = _MenuRECID
FROM tblMenu;
INSERT INTO tblAdmin_Access(RECID,AdminRECID,MenuRECID,Status,CreateUser,CreateDate,AuditUser,AuditDate)
VALUES (UUID(),_AdminRECID,_MenuRECID,'A',_CreateUser,CURDATE(),_AuditUser,CURDATE());
END;
|
|

07-04-11, 03:02
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
Quote:
Originally Posted by ying7690
do you have any sample can let me reference
|
sure, there are examples here: CREATE TRIGGER
|
|

07-04-11, 03:10
|
|
Jaded Developer
|
|
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
|
|
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
|
|

07-04-11, 04:15
|
|
Registered User
|
|
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
|
|
It is not clear what you are trying to achieve with this trigger. Perhaps if you start by providing an explanation we can help?
For instance, you are reading data from the table tblAdmin and also tblMenu. However, if there are many rows in the tblAdmin are you going to process for each one or just the one that is being inserted?
Also how do you get the _MenuRECID value? This is from the tblMenu table but if there are again many values in this table should we process each one or just the first one or can we derive the correct value from the previous result from tblAdmin?
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|