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

  • SEARCH
  • Home
  • 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 402011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:05:10+00:00 2026-05-12T17:05:10+00:00

We have two tables, ActivityForm and Field which are given a many-to-many relationship via

  • 0

We have two tables, ActivityForm and Field which are given a many-to-many relationship via the ActivityFormField table. The ActivityFormFieldValidator table will have a many-to-one relationship with the ActivityFormField table, so we are giving the ActivityFormField table an identity column (“ActivityFormFieldId”). The ActivityFormField table also contains information like the order in which the given field should be displayed on the given activity form.

Expected usage is as follows:

  • There will eventually be a lot of activity forms and fields, but each activity form will only have a handful of fields attached to it (maybe a dozen, on average).
  • The most common query on this table will be to retrieve all of the entries in ActivityFormField table with a given ActivityFormId, and join that data with the Field and ActivityFormFieldValidator tables.
  • New ActivityFormField entries will be created every so often, but not nearly as often as the query mentioned above.

My initial reaction is to configure the ActivityFormField table with the following keys and indexes:

  • Primary Key on the identity column, with a Clustered Index on it.
  • A Unique, nonclustered index that includes the FieldId and ActivityFormId columns.

In addition to feeling the most “right” or “normal” to me, this satisfies the basic requirements of:

  • making sure there is only one ActivityFormField entry for any combination of ActivityForm and Field,
  • providing an indexed key for ActivityFormFieldValidator entries to attach to, and
  • providing an indexed key on ActivityFormId (for the query mentioned earlier)

It also “does no harm” with its clustered index, in the sense that insertion of new ActivityFormField entries shouldn’t cause any reordering of the actual data.

However, given the way that we are planning to use the table, I wonder if there’s another combination of keys and indexes and clustering that is likely to be much more efficient?

Update

Having done some additional research and thinking, I’m leaning toward making my table declaration look something like this:

CREATE TABLE [ActivityFormField](
    [ActivityFormFieldId] [int] IDENTITY(1,1) NOT NULL,
    [ActivityFormId] [int] NOT NULL,
    [FieldId] [int] NOT NULL,
    [SortOrder] [tinyint] NOT NULL,
    CONSTRAINT [PK_ActivityFormField] PRIMARY KEY NONCLUSTERED 
    (
        [ActivityFormFieldId] ASC
    ),
    CONSTRAINT [UK_ActivityFormField_ActivityForm_Field] UNIQUE NONCLUSTERED
    (
        [ActivityFormId] ASC,
        [FieldId] ASC
    )
)

ALTER TABLE [ActivityFormField] WITH CHECK ADD CONSTRAINT [FK_ActivityFormField_ActivityForm] FOREIGN KEY([ActivityFormId])
REFERENCES [ActivityForm] ([ActivityFormId])

ALTER TABLE [ActivityFormField] WITH CHECK ADD CONSTRAINT [FK_ActivityFormField_Field] FOREIGN KEY([FieldId])
REFERENCES [Field] ([FieldId])

CREATE UNIQUE CLUSTERED INDEX IX_ActivityFormField_ActivityForm_SortOrder ON [ActivityFormField] 
(
    [ActivityFormId] ASC,
    [SortOrder] ASC
)

CREATE NONCLUSTERED INDEX IX_ActivityFormField_ActivityForm ON [ActivityFormField] 
    (
        [ActivityFormId]
    )

CREATE NONCLUSTERED INDEX IX_ActivityFormField_Field ON [ActivityFormField] 
    (
        [FieldId]
    )

This approach uses a non-clustered index on the identity field, a clustered index for the criteria and order in which the most commonly-used query will retrieve the data, and a constraint to ensure that only one ActivityFormField entry exists for any combination of ActivityForm and Field. Unique Constraints and Indexes are apparently handled the same way internally, so I chose a constraint to show that its primary purpose is to keep things unique. The other indexes are there “just in case,” following the logic HLGEM proposed.

  • 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-12T17:05:10+00:00Added an answer on May 12, 2026 at 5:05 pm

    Each field that is a separate fk to another table should be in an index all by itself. Unlike PKs these indexes are not created automatically and they will almost always be needed.

    If you have a unique combination other than the PK (and you should if using a surrogate Pk in most tables), by all means put a unique index on the combination of the fields, to fail to do so would be to create data integrity problems. Other indexes may be needed depending on what where clauses you will use in querying the table. Index needs may change as the table size grows, so there is no need to feel you have to get all the indexes right the first time.

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

Sidebar

Related Questions

I have two tables connected with one to many relationship. Parent Table is a
I have two tables: one table (okay, it's a view), vComputer, lists many computers
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables with this structure: Table one: ID Description Table two: ID
I have two tables. One table contains information about Assets, another Table about their
I have two tables. One is temp table and another is main table. In
I have two tables. One table is meant to serve as a transaction history
I have two tables called 'events' and 'topics' each table can have many comments.
I have two tables (renamed/refactored for illustrative purposes) with a Many-To-Many relationship in an
I have two tables a and b . Table a has a field named

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.