TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Software World > Programming

Notices

Change detection in MySQL.

Programming


Reply
 
Thread Tools Display Modes
Old 18-05-2009, 10:47 PM   #11
ƒ(ψ)=ΘΊΧφ
 
bakuryu's Avatar
 
Join Date: May 2006
Location: India
Age: 23
Posts: 6,621
Thanks: 19
Thanked 645 Times in 603 Posts
Rep Power: 87 bakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant future


OS: Windows XP Windows Vista Windows 7


Send a message via Yahoo to bakuryu
Re: Change detection in MySQL.

Quote:
I have seen the IDENTITY property in MSSQL used like:
CREATE TABLE test(idencol INT IDENTITY(1,1), dupcol INT NOT NULL);


I need to create a same query in MySQL. I saw that there is AUTO_INCREMENT in MySQL. But not sure it is the one which I can use instead if identity.

Can you please confirm me or suggest me if I am wrong.
What can I used instead of IDENTITY?
Yes, you need to use AUTO_INCREMENT

Code:
CREATE TABLE test
(
idencol INT NOT NULL AUTO_INCREMENT, 
dupcol INT NOT NULL,
PRIMARY KEY (idencol)
);
For the trigger, what exactly do you want to achieve with the trigger ?
__________________
Please don't click here
bakuryu is offline   Reply With Quote
Thanked Users:
amit_27 (26-05-2009)
Old 19-05-2009, 11:32 AM   #12
Junior Member (25+)
 
Join Date: Jan 2009
Posts: 48
Thanks: 13
Thanked 0 Times in 0 Posts
Rep Power: 0 amit_27 is an unknown quantity at this point


OS: Windows NT / Windows 2000


Re: Change detection in MySQL.

Thanks!

I am creating trigger for before insert, update, delete on table.
amit_27 is offline   Reply With Quote
Old 19-05-2009, 02:24 PM   #13
Junior Member (25+)
 
Join Date: Jan 2009
Posts: 48
Thanks: 13
Thanked 0 Times in 0 Posts
Rep Power: 0 amit_27 is an unknown quantity at this point


OS: Windows NT / Windows 2000


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?
amit_27 is offline   Reply With Quote
Old 19-05-2009, 02:33 PM   #14
Junior Member (25+)
 
Join Date: Jan 2009
Posts: 48
Thanks: 13
Thanked 0 Times in 0 Posts
Rep Power: 0 amit_27 is an unknown quantity at this point


OS: Windows NT / Windows 2000


Re: Change detection in MySQL.

ok. I got the solution for problem. Hence I solved the problem.
amit_27 is offline   Reply With Quote
Old 19-05-2009, 06:04 PM   #15
Junior Member (25+)
 
Join Date: Jan 2009
Posts: 48
Thanks: 13
Thanked 0 Times in 0 Posts
Rep Power: 0 amit_27 is an unknown quantity at this point


OS: Windows NT / Windows 2000


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.
amit_27 is offline   Reply With Quote
Old 19-05-2009, 08:14 PM   #16
ƒ(ψ)=ΘΊΧφ
 
bakuryu's Avatar
 
Join Date: May 2006
Location: India
Age: 23
Posts: 6,621
Thanks: 19
Thanked 645 Times in 603 Posts
Rep Power: 87 bakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant future


OS: Windows XP Windows Vista Windows 7


Send a message via Yahoo to bakuryu
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.
bakuryu is offline   Reply With Quote
Thanked Users:
amit_27 (26-05-2009)
Old 20-05-2009, 04:48 PM   #17
Junior Member (25+)
 
Join Date: Jan 2009
Posts: 48
Thanks: 13
Thanked 0 Times in 0 Posts
Rep Power: 0 amit_27 is an unknown quantity at this point


OS: Windows NT / Windows 2000


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.
amit_27 is offline   Reply With Quote
Old 20-05-2009, 08:09 PM   #18
ƒ(ψ)=ΘΊΧφ
 
bakuryu's Avatar
 
Join Date: May 2006
Location: India
Age: 23
Posts: 6,621
Thanks: 19
Thanked 645 Times in 603 Posts
Rep Power: 87 bakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant future


OS: Windows XP Windows Vista Windows 7


Send a message via Yahoo to bakuryu
Re: Change detection in MySQL.

Quote:
Suppose in case of deletion I want the deleted row information, then I will not have the information after deleting that row.
You can use it using Foreign keys.

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;
This will delete rows in child table automatically when referenced parent is deleted.
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..
bakuryu is offline   Reply With Quote
Thanked Users:
amit_27 (26-05-2009)
Old 26-05-2009, 04:32 PM   #19
Junior Member (25+)
 
Join Date: Jan 2009
Posts: 48
Thanks: 13
Thanked 0 Times in 0 Posts
Rep Power: 0 amit_27 is an unknown quantity at this point


OS: Windows NT / Windows 2000


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?
amit_27 is offline   Reply With Quote
Old 26-05-2009, 05:35 PM   #20
ƒ(ψ)=ΘΊΧφ
 
bakuryu's Avatar
 
Join Date: May 2006
Location: India
Age: 23
Posts: 6,621
Thanks: 19
Thanked 645 Times in 603 Posts
Rep Power: 87 bakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant future


OS: Windows XP Windows Vista Windows 7


Send a message via Yahoo to bakuryu
Re: Change detection in MySQL.

in MySQL it's called information_schema
MySQL :: MySQL 5.0 Reference Manual :: 19 INFORMATION_SCHEMA Tables
bakuryu is offline   Reply With Quote
Reply

Thread Tools
Display Modes



< Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 09:22 AM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional