July 29, 2006 at 5:45 am
hi..
i am new to sql.
i have 2 tables userlogin_details(userid(primary key),username,password), personal_details(userid, name,age,dob)
i set the userid in personal_details table as a foreign key for userlogin_details table..
while i am trying to insert the datas into personal_details table it got entered at first time(i.e the first record of the table). and if second time i entered the data's using the insert command.. the following error is displayed..
Server: Msg 547, Level 16, State 1, Line 1
INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_personal_details_userlogin_details'. The conflict occurred in database 'project', table 'userlogin_details', column 'UserID'.
The statement has been terminated.
plz tell as soon as possible where is the problem.. and how can i rectify it..
with advance thanks..
P.ramasubramanian
July 29, 2006 at 11:14 pm
The error means that the userid you're trying to enter in personal_details doesn't exist in userlogin_details. Solution, enter the data into userlogin_details first.
July 30, 2006 at 11:14 pm
Lance is correct on the cause and resolution of the error.
I would also suggest you relook at the table design. Is there a reason you chose to split out UserLogin and PersonalDetails? It appears that these can reside in a single table as such:
CREATE TABLE Users
( UserID <datatype> PRIMARY KEY
, UserName ...
, Password ...
, Name ...
, Age ...
, DOB ...
)
The case where you couldn't do this is if there are multiple individuals in personal_details for each UserID.
What do you think?
Scott Thornburg
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply