hello to all,

I am using MS SQL 2005. I have 3 tables, COLLAGE, USER, STUDENT
I am providing username & password to collage as well as students.
I wanted to assign Foreign Key to 'username' in both tables College & Student.
i have done,

1. right click on username (college table)
2. click relationsheeps
3.Assign foreign key.

but when I am inserting record, It gives me error that,
Conflict in inserting data.
I don't know how to insert data, means it i insert username in user table, will it automatically pasted in college table or not?

Thank you in advance!

Can you post your table structures and paste the error message from the SQL Server? Please use code tags when pasting:


...code here...


I think u have no clear about the concept of foreign key. Let me explain it. See there is a primary key which is parent column and foreign key which is child of the primary key to have a clear relationships to avoid the mismatches in between the tables. k. As per ur thread, i got an idea that u r trying to create a relationship between the tables college and Student.

You should be clear about columns in the tables and what could be relationship between the tables. Say for example,
Student(Studentid(Primary Key), Studname,dob...)
User (Studentid(Foreign Key , Username, Password)
College(Studentid(Foreign Key),..) (I have no idea whats the purpose of this table.)

Student.Studentid(Primary Key) - Parent
User.Studentid(Foreign Key) - Child

First u have to enter the details in the Student Table and only u can insert the values in the User Table. Because in the Child Table, it will check the values with the parent for every insert and update. So first u enter the values for the Parent Table and then try to enter the details for the Child Table.

Have a nice day
Shailaja M

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.