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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:11:08+00:00 2026-05-28T08:11:08+00:00

I’ve been struggling with how I should indicate that a certain record in a

  • 0

I’ve been struggling with how I should indicate that a certain record in a database is the “fallback” or default entry. I’ve also been struggling with how to reduce my problem to a simple problem statement. I’m going to have to provide an example.

Suppose that you are building a very simple shipping application. You’ll take orders and will need to decide which warehouse to ship them from.

Let’s say that you have a few cities that have their own dedicated warehouses*; if an order comes in from one of those cities, you’ll ship from that city’s warehouse. If an order comes in from any other city, you want to ship from a certain other warehouse. We’ll call that certain other warehouse the fallback warehouse.

You might decide on a schema like this:

Warehouses
    WarehouseId
    Name

WarehouseCities
    WarehouseId
    CityName

The solution must enforce zero or one fallback warehouses.

You need a way to indicate which warehouse should be used if there aren’t any warehouses specified for the city in question. If it really matters, you’re doing this on SQL Server 2008.

EDIT: To be clear, all valid cities are NOT present in the WarehouseCities table. It is possible for an order to be received for a City not listed in WarehouseCities. In such a case, we need to be able to select the fallback warehouse.

If any number of default warehouses were allowed, or if I was assigning default warehouses to, say, states, I would use a DefaultWarehouse table. I could use such a table here, but I would need to limit it to exactly one row, which doesn’t feel right.

How would you indicate the fallback warehouse?


*Of course, in this example we discount the possibility that there might be multiple cities with the same name. The country you are building this application for rigorously enforces a uniqueness constraint on all city names.

  • 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-28T08:11:08+00:00Added an answer on May 28, 2026 at 8:11 am

    I understand your problem, but have questions about parts of it, so I’ll be a bit more general.

    • If at all possible I would store warehouse/backup warehouse data with your inventory data (either directly hanging of warehouses, or if it’s product specific off the inventory tables).
    • If the setup has to be calculated through your business logic then the records should hang off the order/order_item table

    In terms how to implement the structure in SQL, I’ll assume that all orders ship out of a single warehouse and that the shipping must be hung off the orders table (but the ideas should be applicable elsewhere):

    • The older way to enforce zero/one backup warehouses would be to hang a Warehouse_Source record of the Orders table and include an “IsPrimary” field or “ShippingPriority” then include a composite unique index that includes OrderID and IsPrimary/ShippingPriority.

    • if you will only ever have one backup warehouse you could add ShippingSource_WareHouseID and ShippingSource_Backup_WareHouseID fields to the order. Although, this isn’t the route I would go.

    In SQL 2008 and up we have the wonderful addition of Filtered Indexes. These allow you to add a WHERE clause to your index — resulting in a more compact index. It also has the added benefit of allowing you to accomplish some things that could only be done through triggers in the past.

    • You could put a Unique filtered index on OrderID & IsPrimary/ShippingPriority (WHERE IsPrimary = 0).

    Add a comment or such if you want me to explain further.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT

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.