Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
bob123
Starting Member
16 Posts |
Posted - 2010-03-11 : 16:06:25
|
Hi, any help with this appreciatedI have 2 tables QuestionAnswer and SurveyAnswer when I try and import data for the QuestionAnswer table I receive the following error msg..."The INSERT statement conflicted with the FOREIGN KEY constraint "fk_QuestionAnswer_QuestionSection". The conflict occurred in database "ExitSurvey", table "exitsurvey.QuestionSection", column SectionID'.". (SQL Server Import and Export Wizard)CREATE TABLE [XXXX].[QuestionAnswer]( [AnswerID] [int] NOT NULL, [QuestionID] [int] NOT NULL, [SectionID] [int] NULL, [Answer] [varchar](255) NOT NULL, [Type] [char](1) NOT NULL, [Order] [smallint] NULL)ALTER TABLE XXXX.QuestionAnswerADD CONSTRAINT pk_QuestionAnswer PRIMARY KEY (AnswerID)ALTER TABLE XXXX.QuestionAnswerADD CONSTRAINT fk_QuestionAnswer_QuestionSection FOREIGN KEY (SectionID) REFERENCES XXXX.QuestionSection (SectionID) No data in QuestionAnswer table=================================================================CREATE TABLE [XXXX].[QuestionSection]( [SectionID] [int] NOT NULL, [QuestionID] [int] NOT NULL, [SectionHeader] [varchar](255) NOT NULL, [Order] [smallint] NULL)ALTER TABLE XXXX.QuestionSectionADD CONSTRAINT pk_QuestionSection PRIMARY KEY (SectionID)GOALTER TABLE XXXX.QuestionSectionADD CONSTRAINT fk_QuestionSection_Question FOREIGN KEY (QuestionID) REFERENCES exitsurvey.Question (QuestionID) ==================================================================Data in questionsection table1 5 Work conditions or environment 12 5 Work relations 23 5 Professional Development 34 5 Agreement Terminated 45 5 Personal/Family/Whanau Reasons 56 6 Another NZ Health Provider 1 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-03-11 : 17:51:22
|
Seems like you're trying to insert a SectionID into QuestionAnswer that isn't existent in table QuestionSection. No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
bob123
Starting Member
16 Posts |
Posted - 2010-03-11 : 18:58:03
|
Thanks for the reply, I have 2 text files that are supposed to populate these tables I imported the questionsection data without a problem.the questionanswer data is .....AnswerID|QuestionID|SectionID|Answer|Type|Order1|1|-1|0-2 yrs|C|12|1|-1|2-5 yrs|C|23|1|-1|5-10 yrs|C|34|1|-1|10 yrs+|C|45|1|-1|Other|T|56|2|-1|Medical|C|17|2|-1|Public Health|C|28|2|-1|Mental Health|C|39|2|-1|Corporate|C|410|2|-1|Surgical|C|511|2|-1|AT&R & Community|C|612|2|-1|Clinical Support|C|713|2|-1|Funding Division|C|814|2|-1|Child Health|C|915|2|-1|RCTS|C|1016|2|-1|Enable |C|1117|2|-1|Women's Health|C|1218|2|-1|Child & Adolescent Oral Health|C|1319|2|-1|Breast Screening|C|1420|2|-1|M Health|C|1521|2|-1|Other|T|1622|3|-1| North Hospital|C|123|3|-1|PN Community|C|224|3|-1|H|C|325|3|-1|Clevely|C|426|3|-1|D|C|527|3|-1|Community|C|628|3|-1|Other|T|729|4|-1|Administration|C|130|4|-1|Nursing|C|231|4|-1|Allied Health|C|332|4|-1|Non-Clinical Support|C|433|4|-1|Clinical Support|C|534|4|-1|Technical|C|635|4|-1|Medical|C|736|4|-1|Other |T|837|5|1|Physical environment|D|138|5|1|Resources or equipment|D|239|5|1|Terms and conditions of employment|D|340|5|2|Interpersonal relationships|D|141|5|2|Team dynamics|D|242|5|2|Lack of job satisfaction|D|343|5|2|Lack of cultural support/supervision|D|444|5|3|Change in profession/different role|D|145|5|3|Career development opportunities/advancement|D|246|5|3|Study or training|D|347|5|4|End of fixed term agreement|D|148|5|4|Restructuring/redundancy|D|249|5|4|Dismissed|D|350|5|5|Health related|D|151|5|5|Overseas travel|D|252|5|5|Domestic reasons|D|353|5|5|Not returning from parental leave/LWOP|D|454|5|5|Non-work or work accident|D|555|5|5|Retirement|D|656|5|5|Relocating with partner/family|D|757|5|-1|Other|T|158|6|-1|Another DHB|C|159|6|-1|Non Health Sector|C|260|6|-1|Overseas health job|C|361|6|-1|Ceasing work|C|462|6|6|Another Health Provider - Local|C|163|6|6|Another Health Provider - Elsewhere|C|264|6|6|Another Health Provider - NGO|C|365|6|-1|Overseas non-health job|C|566|6|-1|Another position within the M region|C|667|6|-1|Other|T|768|7|-1|Physical environment|C|169|7|-1|Working relationships|C|270|7|-1|Equipment/resources|C|371|7|-1|Acknowlegement/recognition|C|472|7|-1|Support/professional supervision|C|573|7|-1|Communication|C|674|7|-1|Job design|C|775|7|-1|Career/professional development opportunities|C|876|7|-1|Team structure|C|977|7|-1|Cultural support/supervision|C|1078|7|-1|Work flexibility|C|1179|7|-1|Regular performance appraisals/feedback|C|1280|7|-1|Not applicable|C|1381|7|-1|Other|T|1482|8|-1|Professional development|C|183|8|-1|My team|C|284|8|-1|Flexibility e.g. hours|C|385|8|-1|Achievement/challenge|C|486|8|-1|Recognition/support|C|587|8|-1|Work environment|C|688|8|-1|Social opportunities|C|789|8|-1|Other|T|890|9|-1|Yes|C|191|9|-1|No|T|2It would seem that the -1 sectionid which is not in the questionsection table is the problem.But I can't see how this can be resolved as I would have to enter the -1 sectionid for very question into the questionsection table which would be entering duplicate values for the primary key.Any suggestions? |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-03-12 : 01:20:07
|
duplicate values for the primary key?You need only one entry in the questionsection table with the value -1.What is the problem? No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
|
|
|
|
|