![]() |
|
|||||||
| Notices |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 | |
|
ƒ(ψ)=ΘΊΧφ
![]() |
Re: Change detection in MySQL.
Quote:
Code:
CREATE TABLE test ( idencol INT NOT NULL AUTO_INCREMENT, dupcol INT NOT NULL, PRIMARY KEY (idencol) );
__________________
Please don't click here |
|
|
|
|
| Thanked Users: | amit_27 (26-05-2009) |
|
|
#12 |
|
Junior Member (25+)
Join Date: Jan 2009
Posts: 48
Thanks: 13
Thanked 0 Times in 0 Posts
Rep Power: 0
![]() OS:
|
Re: Change detection in MySQL.
Thanks!
I am creating trigger for before insert, update, delete on table. |
|
|
|
|
|
#13 |
|
Junior Member (25+)
Join Date: Jan 2009
Posts: 48
Thanks: 13
Thanked 0 Times in 0 Posts
Rep Power: 0
![]() OS:
|
Re: Change detection in MySQL.
Hi,
I have created a trigger which is giving me an error "ERROR 1415 (0A000): Not allowed to return a result set from a trigger": CREATE TABLE t1(idencol INT AUTO_INCREMENT,DUMMYCOL INT NOT NULL, PRIMARY KEY(CLIDENTCOL)); GO; CREATE TRIGGER tri1 BEFORE INSERT ON t2 FOR EACH ROW BEGIN DECLARE PN INT; DECLARE TAB_COL VARCHAR(10); DECLARE done INT DEFAULT 0; DECLARE TRG_CURSOR CURSOR FOR SELECT FNAME FROM INSERTED; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; OPEN TRG_CURSOR; REPEAT FETCH TRG_CURSOR INTO TAB_COL; IF NOT done THEN BEGIN DELETE FROM amit.t1 WHERE DUMMYCOL = 0; INSERT INTO amit.t1 (DUMMYCOL) VALUES(0); SELECT @PN = @@IDENTITY; INSERT INTO amit.CLtable VALUES (@PN, 14); INSERT INTO amit.CLMtable VALUES (TAB_COL, @PN, 'I'); END; END IF; UNTIL done END REPEAT; CLOSE TRG_CURSOR; END $ I have seen the meaning of the error, however there is no specific code found in my trigger which return resultset or code causing problem for this error? Can you please shed some light on this? |
|
|
|
|
|
#14 |
|
Junior Member (25+)
Join Date: Jan 2009
Posts: 48
Thanks: 13
Thanked 0 Times in 0 Posts
Rep Power: 0
![]() OS:
|
Re: Change detection in MySQL.
ok. I got the solution for problem. Hence I solved the problem.
|
|
|
|
|
|
#15 |
|
Junior Member (25+)
Join Date: Jan 2009
Posts: 48
Thanks: 13
Thanked 0 Times in 0 Posts
Rep Power: 0
![]() OS:
|
Re: Change detection in MySQL.
Is there any default table MySQL Server automatically creates and manages these tables like
INSERTED, DELETED table in MSSQL DUAL table in ORACLE. |
|
|
|
|
|
#16 |
|
ƒ(ψ)=ΘΊΧφ
![]() |
Re: Change detection in MySQL.
Check information_schema database
MySQL :: MySQL 5.0 Reference Manual :: 19 INFORMATION_SCHEMA Tables what i meant is what is the purpose of the trigger, what do you want to do before something is inserted ? From the code it seems you are checking for some duplicate values and then taking specific actions. |
|
|
|
| Thanked Users: | amit_27 (26-05-2009) |
|
|
#17 |
|
Junior Member (25+)
Join Date: Jan 2009
Posts: 48
Thanks: 13
Thanked 0 Times in 0 Posts
Rep Power: 0
![]() OS:
|
Re: Change detection in MySQL.
Trigger is to implement in such a way that it will have to read the informarmation from the default table created internally by MySQL like in MSSQL creates INSERTED, DELETED tables.
Using the inserted and deleted Tables Suppose in case of deletion I want the deleted row information, then I will not have the information after deleting that row. So I need to keep track of this information before into tables so can be viewed anytime by query on my own table. I don't have to use timestamp or autoincrement while creating tables. I need to know that MySQL creates any virtual tables which stores the information as temporary. |
|
|
|
|
|
#18 | |
|
ƒ(ψ)=ΘΊΧφ
![]() |
Re: Change detection in MySQL.
Quote:
Code:
CREATE TABLE parent (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id) ) ENGINE=INNODB; CREATE TABLE child (id INT AUTO_INCREMENT, parent_id INT, FOREIGN KEY (parent_id) REFERENCES parent(id) ON DELETE CASCADE ) ENGINE=INNODB; While inserting to know the value of auto increment coloumn for last insert use : LAST_INSERT_ID() function or in php : PHP: mysql_insert_id - Manual (for php) otherwise you can use Replication : MySQL :: MySQL 5.0 Reference Manual :: 16 Replication However you can create views with MySQL also. http://dev.mysql.com/doc/refman/5.0/en/create-view.html Last edited by bakuryu; 20-05-2009 at 08:11 PM.. |
|
|
|
|
| Thanked Users: | amit_27 (26-05-2009) |
|
|
#19 |
|
Junior Member (25+)
Join Date: Jan 2009
Posts: 48
Thanks: 13
Thanked 0 Times in 0 Posts
Rep Power: 0
![]() OS:
|
Re: Change detection in MySQL.
What is the default schema name in MySQL 5.1.34 like in ORACLE is username (system), in MSSQL is "dbo"?
I think it is database name Isn't it? |
|
|
|
|
|
#20 |
|
ƒ(ψ)=ΘΊΧφ
![]() |
Re: Change detection in MySQL.
in MySQL it's called information_schema
MySQL :: MySQL 5.0 Reference Manual :: 19 INFORMATION_SCHEMA Tables |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
< Windows Help - MS Office Help - Hardware Support >
| New To Site? | Need Help? |