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 294711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:23:30+00:00 2026-05-12T06:23:30+00:00

Given the following structure: City Area User Every Area has 1 and only 1

  • 0

Given the following structure:

City
Area
User

Every Area has 1 and only 1 City.
Every User has at least one but possibly multiple Areas.
Every User has 1 and only 1 City.

What is the most elegant way to model this?

Currently, I have:

User,
UserArea,
Area,
City

Where UserArea is a 1:M relationship w/ User, and Area is 1:1 with City.

The problem is this:

A user can have 3 or 4 Areas under the current model, but 2 of the Areas could be in City “1” and the other 2 Areas could be in City “2”. This is a violation of business rules.

Should I just put in a constraint to prevent this sort of thing, or is a better approach to normalize further so that this type of paradox is not possible? If so, how does one model this system so that:

1 User = 1 City;
1 Area = 1 City;
1 User = M Areas;

Thanks for you insights.

  • 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-12T06:23:31+00:00Added an answer on May 12, 2026 at 6:23 am

    This answer was provided to me from SQLServerCentral, and it does exactly what I was looking for. There is a redundancy (as rexum pointed out in this forum), but there is no possibility of anomolies.

    I’m very interested in your comments and suggestions.


    CREATE TABLE [dbo].[Cities](
        [CityID] [int] IDENTITY(1,1) NOT NULL,
      [CityName] [varchar](50) NOT NULL,
     CONSTRAINT [PK_Cities] PRIMARY KEY CLUSTERED
    (
       [CityID] ASC
    )
    )
    CREATE TABLE [dbo].[Users](
       [UserID] [int] IDENTITY(1,1) NOT NULL,
      [UserName] [varchar](50) NOT NULL,
      [CityID] [int] NOT NULL,
     CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
    (
      [UserID] ASC
    )
    )
    
    ALTER TABLE [dbo].[Users]  WITH CHECK ADD  CONSTRAINT [FK_Users_Cities] FOREIGN KEY([CityID])
    REFERENCES [dbo].[Cities] ([CityID])
    GO
    ALTER TABLE [dbo].[Users] CHECK CONSTRAINT [FK_Users_Cities]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IX_UsersCity] ON [dbo].[Users]
    (
       [UserID] ASC,
       [CityID] ASC
    )
    
    CREATE TABLE [dbo].[Areas](
        [AreaID] [int] IDENTITY(1,1) NOT NULL,
      [AreaName] [varchar](50) NOT NULL,
      [CityID] [int] NOT NULL,
     CONSTRAINT [PK_Areas] PRIMARY KEY CLUSTERED
    (
      [AreaID] ASC
    ))
    
    
    GO
    ALTER TABLE [dbo].[Areas]  WITH CHECK ADD  CONSTRAINT [FK_Areas_Cities] FOREIGN KEY([CityID])
    REFERENCES [dbo].[Cities] ([CityID])
    GO
    ALTER TABLE [dbo].[Areas] CHECK CONSTRAINT [FK_Areas_Cities]
    GO
    CREATE UNIQUE NONCLUSTERED INDEX [IX_AreasCity] ON [dbo].[Areas]
    (
     [AreaID] ASC,
       [CityID] ASC
    )
    GO
    CREATE TABLE [dbo].[UserCityArea](
       [UserID] [int] NOT NULL,
        [CityID] [int] NOT NULL,
        [AreaID] [int] NOT NULL,
     CONSTRAINT [PK_UserCityArea] PRIMARY KEY CLUSTERED
    (
       [UserID] ASC,
       [CityID] ASC,
       [AreaID] ASC
    )
    )
    
    GO
    ALTER TABLE [dbo].[UserCityArea]  WITH CHECK ADD FOREIGN KEY([UserID], [CityID])
    REFERENCES [dbo].[Users] ([UserID], [CityID])
    GO
    ALTER TABLE [dbo].[UserCityArea]  WITH CHECK ADD FOREIGN KEY([AreaID], [CityID])
    REFERENCES [dbo].[Areas] ([AreaID], [CityID])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following table structure: CREATE TABLE user ( uid INT(11) auto_increment, name VARCHAR(200),
Given following structure: a person has functions. Each function has roles. Each roles has
Given the following XML structure <html> <body> <div> <span>Test: Text2</span> </div> <div> <span>Test: Text3</span>
I have an odd linq subquery issue. Given the following data structure: Parents Children
I have a necessity to sort a given HTML table of the following structure,
Following class structure is given: class Job { String description; Collection<JobHistory> history; } class
Given a pretty basic source tree structure like the following: trunk ------- QA |--------
I have the following tables structure: Shipment (has IDDestination as foreign key) -> Destination
Given the following structure typedef struct { float3 position; float8 position1; } MyStruct; I'm
Given the following structure: struct nmslist_elem_s { nmptr data; struct nmslist_elem_s *next; }; typedef

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.