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 |  
                                    | Jouni79Starting Member
 
 
                                        9 Posts | 
                                            
                                            |  Posted - 2009-03-10 : 03:35:56 
 |  
                                            | Hello everyone.I hope I put this in right area. I want to ask your opinion. How to check is foreign key in use .Now  when  try to delete record witch have reference to other table. now I get The DELETE statement conflicted with the REFERENCE constraint. I want to just check if foreign key is in use. |  |  
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2009-03-10 : 04:20:14 
 |  
                                          | just check the table in which fk is referenced using IF NOT EXISTS IF NOT EXISTS(SELECT 1 FROM ChildTable WHERE fk= yourvalue)DELETE m FROM Master m WHERE m.pk=yourvalueor if you want to do all of deletes in batch then use DELETE mFROM Master mLEFT JOIN Child cON c.fk=m.pkWHERE c.fk IS NULL |  
                                          |  |  |  
                                    | Jouni79Starting Member
 
 
                                    9 Posts | 
                                        
                                          |  Posted - 2009-03-11 : 03:13:32 
 |  
                                          | Thank you.That helped me. |  
                                          |  |  |  
                                |  |  |  |