Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Location
    Alpine Califormia
    Posts
    1,789

    Unanswered: Relationship Error

    Hi guys I had to import a table into sql from Access and it needs to be Joined with another table on sql server. but I am getting a Error. How do I deal with this??
    'People_tbl' table saved successfully
    'Contact_sc' table
    - Unable to create relationship 'FK_Contact_sc_People_tbl'.
    The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_Contact_sc_People_tbl". The conflict occurred in database "SCAIR", table "dbo.People_tbl", column 'Parent ID'.

    Code:
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Contact_sc](
    	[ID] [int] NOT NULL,
    	[Contact Date] [datetime] NULL,
    	[Parent ID] [nvarchar](50) NULL,
    	[Type of Contact] [nvarchar](50) NULL,
    	[Purpose of Contact] [nvarchar](max) NULL,
    	[Referral Date] [datetime] NULL,
    	[Earned hours] [float] NULL,
    	[Catagory for hours] [nvarchar](255) NULL,
    	[Services Covered] [nvarchar](255) NULL,
    	[State Catagory] [nvarchar](255) NULL,
    	[State Services Covered] [nvarchar](255) NULL,
     CONSTRAINT [PK_Contact_sc] PRIMARY KEY CLUSTERED 
    (
    	[ID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]



    Code:
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[People_tbl](
    	[Parent ID] [nvarchar](50) NOT NULL,
    	[Family ID] [nvarchar](50) NULL,
    	[StudtID] [nvarchar](50) NULL,
    	[Date of Referral] [nvarchar](50) NULL,
    	[Parent First Name] [nvarchar](50) NULL,
    	[Parent Last Name] [nvarchar](50) NULL,
    	[Parent SS#] [nvarchar](50) NULL,
    	[DOB] [datetime] NULL,
    	[Sex] [nvarchar](50) NULL,
    	[Telephone #] [nvarchar](50) NULL,
    	[Message #] [nvarchar](50) NULL,
    	[Address] [nvarchar](50) NULL,
    	[City] [nvarchar](50) NULL,
    	[State] [nvarchar](50) NULL,
    	[Zip] [nvarchar](50) NULL,
    	[E Mail Address] [nvarchar](50) NULL,
    	[Tribal Affiliation] [nvarchar](50) NULL,
    	[Event ID] [nvarchar](50) NULL,
    	[TANF staff making Referral] [nvarchar](50) NULL,
    	[ReferralLocation] [nvarchar](50) NULL,
    	[RegistrationDate] [datetime] NULL,
    	[Type Participant] [nvarchar](50) NULL,
    	[Required hours] [int] NULL,
    	[Special Instrution] [nvarchar](max) NULL,
    	[GED] [bit] NULL,
    	[High School Diploma] [bit] NULL,
    	[Drivers License] [bit] NULL,
    	[Assessement Date] [bit] NULL,
    	[Assessement] [datetime] NULL,
    	[Career Assessment Date] [bit] NULL,
    	[Career Assessment] [datetime] NULL,
    	[Other] [bit] NULL,
    	[Explain Other] [nvarchar](50) NULL,
    	[GED/High School Diploma-VC Adult School] [nvarchar](50) NULL,
    	[Higher Education] [nvarchar](50) NULL,
    	[Culture] [nvarchar](50) NULL,
    	[Community Service] [nvarchar](50) NULL,
    	[Vocational] [nvarchar](50) NULL,
    	[DMV] [nvarchar](50) NULL,
    	[SchoolAddress] [nvarchar](50) NULL,
    	[SchoolName] [nvarchar](50) NULL,
    	[SchoolPhone] [nvarchar](50) NULL,
    	[SchoolCity] [nvarchar](50) NULL,
    	[SchoolState] [nvarchar](50) NULL,
    	[SchoolZip] [nvarchar](50) NULL,
    	[TimeSchoolStart] [datetime] NULL,
    	[TimeSchoolEnds] [datetime] NULL,
    	[StudentGPA] [nvarchar](50) NULL,
    	[Grade] [nvarchar](50) NULL,
    	[Age] [nvarchar](50) NULL,
    	[StudentschoolID] [nvarchar](50) NULL,
    	[SchoolID] [nvarchar](50) NULL,
    	[StudentRelease] [nvarchar](50) NULL,
    	[ParentRelease] [nvarchar](50) NULL,
    	[DateOfRelease] [datetime] NULL,
    	[TanfReferral] [nvarchar](50) NULL,
     CONSTRAINT [PK_Parent] PRIMARY KEY CLUSTERED 
    (
    	[Parent ID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    uhhhhhhhh... what ALTER TABLE statement? which FOREIGN KEY constraint?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2004
    Location
    Alpine Califormia
    Posts
    1,789
    [Parent ID] would be the foreign key in the Contact_sc . sorry about that what I was wantig to know is how would I alter the table so that there can be a relationship between the two?? I just imported the table and tried to create a relationship with the foreign key [parent id] to the People_tbls primary key [Parent Id] and I got that error
    Last edited by desireemm; 08-04-09 at 00:49.

  4. #4
    Join Date
    Feb 2004
    Location
    Alpine Califormia
    Posts
    1,789
    Nevermind got it

    Alter Table [Contact_sc] with no check add constraint [FK_Contact_sc_People_tbl] foreign key ([Parent id])
    REFERENCES [People_tbl]([Parent ID])

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •