Click here to Skip to main content
15,944,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
in my first tbl_uni

Uni_id,University_Name are the columns

in tbl_course

C_id,University_name,Course,Major,Uni_id(FK refer tbl_uni)

in tbl_major

Mid,University_name,Course,Major,Uni_id(FK refer tbl_uni),C_id(FK refer tbl_course)

while inserting the vale by dropdownlist in tbl_course


the error will be

The INSERT statement conflicted with the FOREIGN KEY constraint "FK__tbl_cours__Uni_i__36B12243". The conflict occurred in database "University", table "dbo.tbl_university", column 'Uni_id'.
Arasappan 22-Jun-15 2:21am    
While searching,Resource id is the element to solve this,I got it,but i dont know how to use it.
Ragul M 22-Jun-15 2:31am    
First poi tbl_uni column Uni_id antha ID eruka nu paru apparam vanthu insert pannu..
Arasappan 22-Jun-15 2:41am    
Uni_id University_Name

13 annna

yes Uni_id is in the uni table

First thing first, the database design is totally unacceptable:
1. Why is university_name appears in tbl_course and tbl_major?
2. Why is course appears in tbl_major?
3. Why is major appears in tbl_course?
You are duplicating data and that shows your tables are not properly normalized. Normalization of Database[^]
Next, the error stated that you attempted to insert a new uni_id into the tbl_course (child) and that uni_id did not exist in the tbl_uni table (parent). Read more SQL FOREIGN KEY Constraint[^]
Learn more:[^]
Share this answer
Arasappan 22-Jun-15 3:23am    
1.I want to insert the university name in table course
2.Similar to that i bind course in major
3.Finally i need to combine in a single table
Peter Leow 22-Jun-15 3:52am    
You don't get it, do you?
There is no need to insert university name to course table, it only belongs to uni table.
You database design is totally wrong. Study the links that I have provided, and re-design the database tables.
Otherwise, no point moving forward from a wrong start point. You are just going to make things worse.
Arasappan 22-Jun-15 5:16am    
Yup,Now only got ypu,thank you for the links ypu suggested.:-)
Below query will be helpful in finding the linkage of PK and FK of your Database.
For more easier you can use Database diagram also.
SELECT AS ForeignKey,
OBJECT_NAME(f.parent_object_id) AS TableName,
COL_NAME(fc.parent_object_id,fc.parent_column_id) AS ColumnName,
SCHEMA_NAME(o.SCHEMA_ID) ReferenceSchemaName,
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
COL_NAME(fc.referenced_object_id,fc.referenced_column_id) AS ReferenceColumnName
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id
INNER JOIN sys.objects AS o ON o.OBJECT_ID = fc.referenced_object_id
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900