foreign key problem

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 4
Reputation: bozkurt is an unknown quantity at this point 
Solved Threads: 0
bozkurt bozkurt is offline Offline
Newbie Poster

foreign key problem

 
0
  #1
Apr 16th, 2009
Hi, I am new.
I have two table like this

  1. CREATE table1(
  2. ID VARCHAR(10),
  3. CONSTRAINT PKeyt1 PRIMARY KEY (ID)
  4. )
  5.  
  6. CREATE table2(
  7. ID1 VARCHAR(10),
  8. ID2 VARCHAR(10)
  9. )

I want to add foreign key to table2 which ID1 and ID2 is different but referenced same column ID and ON UPDATE CASCADE. I tried every way which I now but I get this error


Msg 1785, Level 16, State 0, Line 2
Introducing FOREIGN KEY constraint 'blabla' on table 'blabla' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.


How can I do this or can sql do this ) thanks for reply...
Last edited by bozkurt; Apr 16th, 2009 at 1:01 am. Reason: font character
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 217
Reputation: mail2saion is an unknown quantity at this point 
Solved Threads: 31
mail2saion's Avatar
mail2saion mail2saion is offline Offline
Posting Whiz in Training

Re: foreign key problem

 
0
  #2
Apr 16th, 2009
HI, Hope the below link will help you a lot.
http://support.microsoft.com/kb/321843
Last edited by mail2saion; Apr 16th, 2009 at 1:49 am.
MARK AS SOLVED if its help you.

REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 4
Reputation: bozkurt is an unknown quantity at this point 
Solved Threads: 0
bozkurt bozkurt is offline Offline
Newbie Poster

Re: foreign key problem

 
0
  #3
Apr 16th, 2009
No it isnt help to me because I want to add ON UPDATE CASCADE foreach key but in this link used ON UPDATE CASCADE just for one key... Can we do foreach key in mssql?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: foreign key problem

 
0
  #4
Apr 16th, 2009
You can use triggers as said in the KB.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 4
Reputation: bozkurt is an unknown quantity at this point 
Solved Threads: 0
bozkurt bozkurt is offline Offline
Newbie Poster

Re: foreign key problem

 
0
  #5
Apr 16th, 2009
I do that ON UPDATE NO ACTION ON DELETE NO ACTION but I am very bad in trigger Can anybody give simple example for trigger?
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 4
Reputation: bozkurt is an unknown quantity at this point 
Solved Threads: 0
bozkurt bozkurt is offline Offline
Newbie Poster

Re: foreign key problem

 
0
  #6
Apr 16th, 2009
Thanks for reply I do trigger bu I get error when I update row like this:

The UPDATE statement conflicted with the REFERENCE constraint "blabla". The conflict occurred in database "blabla", table "blabla".

I think my wrong in describing foreign key. I did it like this
  1. ALTER TABLE blabla ADD CONSTRAINT blabla FOREIGN KEY (blabla,blabla) REFERENCES blabla(blabla,blabla) ON UPDATE NO ACTION ON DELETE NO ACTION
Can anybody have an idea?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: foreign key problem

 
0
  #7
Apr 17th, 2009
blabla blabla blabla I don't understand anything.
Logically you need to update the two columns of table2 when the primary key of table1 changes?
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC