Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3214936
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:07:09+00:00 2026-05-17T15:07:09+00:00

My table schema is something like this 1. Master table : Clause Columns ClauseID

  • 0

My table schema is something like this

1. Master table : Clause

Columns

  1. ClauseID = surrogate pk (identity)
  2. ClauseCode = nvarchar user specified value
  3. Class = nvarchar FK to a master class table
  4. etc…

ClauseCode + Class = candidate key for this table

2. Master table : GroupClause

Columns

  1. GroupClauseID = surrogate pk (identity)
  2. GroupClauseCode = nvarchar user specified value
  3. Class = nvarchar FK to a master class table
    etc…

GroupClauseCode + Class = candidate key for this table

3. Transaction / Mapping table :: GroupClause_Clause_Mapping : this table maps each group clause to multiple individual clauses

Columns

  1. GroupClauseID = FK to GroupClause PK
  2. ClauseID = FK to Clause PK
  3. etc…

Requirement : Each Group clauses can only be mapped to clauses belonging to the same class as itself

Issue : This above table design does not enforce that requirement at a DB level.

One possible solution : Table *GroupClause_Clause_Mapping* has columns

  1. ClauseCode
  2. GroupClauseCode
  3. Class

wherein i can create ClauseCode + Class as FK to clause table as well as GroupClauseCode
+ Class as FK to GroupClause table.

However, if i do it this way, then the surrogate identity keys are useless and i might as well get rid of them.

Is there an issue with my design using the surrogate keys?

Any suggestions as to how i can use the surrogate keys and still enforce my constraint at a DB level?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:07:09+00:00Added an answer on May 17, 2026 at 3:07 pm

    If the Codes themselves are large/unwieldy, then you may still want to use the surrogates, where available.

    Since you only want to enforce the classes matching, then your mapping table could be

    ClauseID,
    GroupClauseID,
    Class (or possibly ClassID)
    

    For your master tables, you’d still have PK (ClauseID), and a unique constraint (ClauseID, Class). You can then decide whether to just FK (ClauseID,Class) or to have two FKs between the mapping table and each master table (effectively, you’d then be saying that one FK is the foreign key reference, and the other is there to enforce your rules).

    I’ve got a similar setup in one of my databases (think survey system):

    CREATE TABLE [dbo].[DataItems](
        [DataItemID] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
        [TypeRequired] [varchar](10) NOT NULL,
        [Name] [varchar](50) NOT NULL,
        /* Other Columns */
     CONSTRAINT [PK_DataItems] PRIMARY KEY NONCLUSTERED 
    (
        [DataItemID] ASC
    ),
     CONSTRAINT [UX_DataItems_ClientAnswerFKTarget] UNIQUE CLUSTERED 
    (
        [DataItemID] ASC,
        [TypeRequired] ASC
    ),
     CONSTRAINT [UX_DataItems_Name] UNIQUE NONCLUSTERED 
    (
        [Name] ASC
    )
    )
    
    CREATE TABLE [dbo].[ClientAnswers](
        [ClientAnswersID] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
        [ClientID] [uniqueidentifier] NOT NULL,
        [DataItemID] [uniqueidentifier] NOT NULL,
        [TypeRequired] [varchar](10) NOT NULL,
        [BoolValue] [bit] NULL,
        [IntValue] [int] NULL,
        [CharValue] [varchar](6500) NULL,
        [CurrencyValue] [int] NULL,
        [DateValue] [datetime] NULL,
        /* Other Columns */
     CONSTRAINT [PK_ClientAnswers] PRIMARY KEY CLUSTERED 
    (
        [ClientID] ASC,
        [DataItemID] ASC
    )
    )
    GO
    ALTER TABLE [dbo].[ClientAnswers] ADD  CONSTRAINT [FK_ClientAnswers_DataItems] FOREIGN KEY([DataItemID],)
    REFERENCES [dbo].[DataItems] ([DataItemID])
    ON UPDATE CASCADE
    GO
    ALTER TABLE [dbo].[ClientAnswers] ADD  CONSTRAINT [FK_ClientAnswers_DataItems_TypesMatch] FOREIGN KEY([DataItemID],TypeRequired)
    REFERENCES [dbo].[DataItems] ([DataItemID],TypeRequired)
    GO
    

    And then I go further and have more constraints ensuring that the type column matches the non-null *Value column

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The basic table schema looks something like this (I'm using MySQL BTW): integer unsigned
My schema looks something like this: CREATE TABLE plans ( id SERIAL PRIMARY KEY,
Table schema is set up something like this: userID Points timestamp 1 40 3
I have a table in PostgreSQL where the schema looks like this: CREATE TABLE
I have a table named Info of this schema: int objectId; int time; int
Something like this: SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME ='FK_TreeNodesBinaryAssets_BinaryAssets' and TABLE_NAME = 'TreeNodesBinaryAssets'
I have a table with this schema: DeviceID int RoomID int DateInstalled datetime A
Which Database table Schema is more efficient and why? Users (UserID, UserName, CompamyId) Companies
I have the following table schema; CREATE TABLE `db1`.`sms_queue` ( `Id` INTEGER UNSIGNED NOT
As in subject... is there a way of looking at an empty table schema

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.