Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with.
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | amostohStarting Member
 
 
                                        1 Post | 
                                            
                                            |  Posted - 2014-03-10 : 05:56:33 
 |  
                                            | Hi allwill appreciate some help to debug the following trigger which is not inserting any data into `DUMPINGGRD`: quote:The following is the structure of the tables involved:delimiter $$ CREATE TRIGGER ins_File BEFORE INSERT ON REPORT FOR EACH ROW BEGIN set @filenum=(Select max(File_Id) from DUMPINGGRD);  if(@filenum=0) then  --checking whether record is present or notbeginnew.File_Id=1;--if no record is present then set file_id=1 end;elsenew.File_Id=@filenum+1;--if record is present then set file_id=Maxvalue+1;end if;     INSERT INTO DUMPINGGRD (File_Id) VALUES (NEW.File_Id);     END$$ delimiter ;
 
 quote:CREATE TABLE REPORT ( R_Id int(10) NOT NULL AUTO_INCREMENT,R_Type varchar(255) not null,R_Title varchar(255) not null,U_Id int(10) not null,File_Id int(10) not null,  PRIMARY KEY (R_Id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
 quote:CREATE TABLE `DUMPINGGRD`(`File_Id` int(10) NOT NULL,`File_Name` varchar(255),`UploadDate` date, PRIMARY KEY (`File_Id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
 quote:ALTER TABLE  `REPORT` ADD CONSTRAINT  `fk_report` FOREIGN KEY (`File_Id`)REFERENCES `DUMPINGGRD` (`File_Id`) ON UPDATE CASCADE;
 
 |  |  
                                    | maunishqYak Posting Veteran
 
 
                                    71 Posts | 
                                        
                                          |  Posted - 2014-03-10 : 15:42:30 
 |  
                                          | Hi,Which database are you using? SQL Server does not have a clause with BEFORE INSERT. You should use INSTEAD OF INSERT syntax for before insert trigger in SQL Server.=======================Not an Expert, Just a learner.!_(M)_! |  
                                          |  |  |  
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2014-03-11 : 05:30:42 
 |  
                                          | I can see InnoDB so its MYSQL I reckon. Please post in some MySQL forums in that case. This forum is MS SQL Server specific------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |  
                                          |  |  |  
                                |  |  |  |