Skip to content

Conversation

Copy link

Copilot AI commented Oct 27, 2025

Implements a composite key example using Freudian psychology concepts (id, ego, superego) to demonstrate multi-column primary keys and foreign key relationships.

Files Added

Implementation (T-Sql/id-ego-superego-composite-key.tsql, 355 lines)

  • PsychologicalState table with composite PK (id, ego, superego)
  • 3 child tables (PsychologicalConflict, BehavioralOutcome, PsycheMetrics) with composite FKs
  • 10 sample states demonstrating unique combinations: (1,1,1), (2,1,1), (1,1,2), etc.
  • Query examples: joins, CTEs, window functions, component dominance analysis

Documentation (CompositeKeys.md, 303 lines)

  • When to use: junction tables, time-series, no natural single key
  • Tradeoffs: semantic clarity vs join complexity
  • Composite vs surrogate key comparison

Quick Reference (T-Sql/id-ego-superego-composite-key-QUICK-REFERENCE.md, 204 lines)

  • ASCII diagram of table relationships
  • Common patterns: exact match, joins, partial key searches

Example

-- Composite primary key
CREATE TABLE PsychologicalState (
    id INT NOT NULL,
    ego INT NOT NULL,
    superego INT NOT NULL,
    stateName VARCHAR(100),
    CONSTRAINT PK_PsychologicalState PRIMARY KEY (id, ego, superego)
);

-- Child table with composite FK
CREATE TABLE PsychologicalConflict (
    conflictId INT PRIMARY KEY IDENTITY(1,1),
    id INT NOT NULL,
    ego INT NOT NULL,
    superego INT NOT NULL,
    conflictType VARCHAR(50),
    CONSTRAINT FK_Conflict_State FOREIGN KEY (id, ego, superego)
        REFERENCES PsychologicalState(id, ego, superego)
);

-- Joining requires all key columns
SELECT ps.stateName, pc.conflictType
FROM PsychologicalState ps
JOIN PsychologicalConflict pc 
    ON ps.id = pc.id 
    AND ps.ego = pc.ego 
    AND ps.superego = pc.superego;

Individual columns are non-unique (id=1 appears in multiple rows), but combinations are unique ((1,1,1)(1,2,1)(2,1,1)).

Original prompt

This section details on the original issue you should resolve

<issue_title>id-ego-superego as composite key</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Oct 27, 2025
Copilot AI and others added 2 commits October 27, 2025 00:25
Co-authored-by: ewdlop <25368970+ewdlop@users.noreply.github.com>
Co-authored-by: ewdlop <25368970+ewdlop@users.noreply.github.com>
Copilot AI changed the title [WIP] Add composite key for id, ego, and superego Add composite key demonstration using id-ego-superego Oct 27, 2025
Copilot AI requested a review from ewdlop October 27, 2025 00:29
Copilot finished work on behalf of ewdlop October 27, 2025 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

id-ego-superego as composite key

2 participants