Table PERSON vs EPISODE) foreign key columns to match exactly
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 1.1k
- Forks
- 508
- Avg merge
- 1h 30m
- Merged PRs (30d)
- 3
Description
SQL Server requires foreign key columns to match exactly.
integer ≠ bigint, so SQL Server refuses to create the FK
How to Fix It
You have two options — choose the one that matches your data model.
Option 1 — Make PERSON.person_id a BIGINT
This is the most common fix if your IDs can grow large.
Option 2,. Not fit for us, as int is not appropriate for person key.
Important Note (OMOP CDM)
Since you’re clearly building OMOP CDM:
PERSON.person_id must be BIGINT
EPISODE.person_id must also be BIGINT
So you’re absolutely doing the right thing.
===============================================
ALTER TABLE PERSON
ALTER COLUMN person_id BIGINT NOT NULL;
ALTER TABLE EPISODE
ADD CONSTRAINT fpk_EPISODE_person_id
FOREIGN KEY (person_id) REFERENCES PERSON(person_id);
ALTER TABLE PERSON
DROP CONSTRAINT xpk_PERSON;
ALTER TABLE PERSON
ALTER COLUMN person_id BIGINT NOT NULL;
ALTER TABLE PERSON
ADD CONSTRAINT xpk_PERSON PRIMARY KEY (person_id);
ALTER TABLE EPISODE
DROP CONSTRAINT fpk_EPISODE_person_id;
ALTER TABLE EPISODE
ADD CONSTRAINT fpk_EPISODE_person_id
FOREIGN KEY (person_id) REFERENCES PERSON(person_id);
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the PERSON and EPISODE table definitions and their key constraints in the repository's DDL. Compare the person_id types, then verify that both use BIGINT and that the foreign key can be created successfully on SQL Server.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100