home »forums »general topics »faq - frequently asked questions »Related To Sql server database

Related To Sql server database

Topic RSS Feed

Posts under the topic: Related To Sql server database

Posted: 11/14/2009 7:03:23 AM

Lurker 180 points Lurker
  • Joined on: 10/23/2009 2:43:08 AM
  • Posts: 14

hi

i have one problem

i have three tables named QuestionTable which have the primarey ker question_id

which refrances

two other tables named as Answer and Exam_Quesion so when i want to delete the data from question table then

 no data had dellted and exception is occuering

please help me thanks

naval kishor pandey

 


Posted: 11/14/2009 7:28:28 AM

Professional 9529 points Professional
  • Joined on: 4/19/2009 1:46:52 AM
  • Posts: 219
answered  Answered

Hi, Naval

Yes you can't delete data from your parent table until you have data in your child tables. You have foreign key on your child tables which points to primary key in the main table so thats why you can t delete directly from parent table having primary key. If you are still in dilemma then please post  some test data .

 

Thanks,

Raghav


Posted: 11/14/2009 10:37:15 AM

Contributor 2596 points Contributor
  • Joined on: 11/29/2008 6:26:22 AM
  • Posts: 53
answered  Answered

Hi Naval,
If you want to delete the data from Question(Parent  table) then first you need to delete data from Answer,Exam_Question (Child table) like:

Delete from Answer where QuestionId=@QuestionID
Delete from Exam_Question where QuestionId=@QuestionID
Delete from Question where QuestionId=@QuestionID



Posted: 11/14/2009 10:39:55 AM

Lurker 180 points Lurker
  • Joined on: 10/23/2009 2:43:08 AM
  • Posts: 14

Thanks

Mr. Vijendar and raghav

My problem is solved.

naval kishor Pandey

 


Posted: 11/14/2009 12:41:20 PM

Professional 9529 points Professional
  • Joined on: 4/19/2009 1:46:52 AM
  • Posts: 219

Cool.Cool


Page 1 of 1 (5 items)