i have two tables tblCourse,tblCourseEnquiry tblCourse have column name PK_CourseId and tblCourseEnquiry have FK_CourseId. i have established relationshib between them (PK,FK)so when i try to delete any tblCourse record dey give some error like below The DELETE statement conflicted with the REFERENCE constraint "FK_tblCourseEnquiry_tblCourse". The conflict occurred in database "VInfotech", table "dbo.tblCourseEnquiry", column 'FK_CourseId'. The statement has been terminated.
This is because deleting the record in tblCourse would leave a record in tblCourseEnquiry 'orphaned', it would have no PK to link to. You will have to delete the tblCourseEnquiry records that have the FK value of the record you want to delete in tblCourse and THEN delete the record from tblCourse
Fatherjack is right, but you have a second option. You can alter your foreign key to use cascade delete. That is, you can delete records from the primary table and all corresponding records from the related table will be deleted. It will make it easier to delete records from a table with foreign keys, but it is usually not recommended for a couple of reasons: - You have no control over the delete process. Deleting one record from primary table can cause a delete of millions of records from related table. - If you accidentially delete a record, you will not get an error and all corresponding records will also be deleted. If I spend a little more time, I can probably remember some additional reasons to avoid cascading delets, but time is a bottleneck... :)