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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:05:02+00:00 2026-05-14T06:05:02+00:00

What is the best way to translate the following problem in SQL table structure:

  • 0

What is the best way to translate the following problem in SQL table structure:

In a file transfer application, I have a master table with an “Upload type” field. Depending on the value of that field (FTP, SFTP, HTTPS, FS copy) the record is to be linked with other entries in the appropriate table (FTPsites, HTTPSSites, etc.) containing the relevant details.

This master table has several similar “switch” fields (upload, download, encryption, decryption, and a few application-related ones).

Currently, the table has a different field for each possible target table. This allows me to keep integrity constrains on the table but that’s a lot of fields which are going to be NULL.

Is there a better schema for solving that problem ?

In case it’s relevant, the target DB is MS SQL 2008

  • 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-14T06:05:02+00:00Added an answer on May 14, 2026 at 6:05 am

    What you are describing is a database design issue akin to implementing table inheritance (where your master table is the parent and your type-specific tables are the children). You can see a really good explanation of how to implement table inheritance with SQL Server 2005/2008 here:

    http://www.sqlteam.com/article/implementing-table-inheritance-in-sql-server

    …but I will adapt the design pattern in that article to your specific case below.

    First, you need a new table to hold your possible list of UploadTypes:

    create table UploadType 
    (
        UploadTypeID int primary key,
        UploadTypeDesc varchar(50)
    )
    

    Now, make sure your MasterTable has a foreign key to the UploadType table and add an additional UNIQUE constraint to your master table on the fields MasterTableID and UploadTypeID:

    create table MasterTable
    (
      MasterTableID int primary key, 
      UploadTypeID int references UploadType(UploadTypeID), 
      -- ...Other fields...
      constraint MasterTable_AltPK unique (MasterTableID,UploadTypeID)
    )
    

    Assuming you have inserted values into the UploadType table so that HTTP uploads have an UploadTypeID = 1, FTP uploads have an UploadTypeID = 2, and SFTP uploads have an UploadTypeID = 3, you can set now up your upload-specific tables as follows (explanation at the end):

    create table HTTPSites 
    (
      HTTPSiteID int primary key, 
      UploadTypeID as 1 persisted, -- computed column; explanation below
      -- ...Other fields...
      foreign key (MasterTableID, UploadTypeID) references MasterTable(MasterTableID, UploadTypeID)
    )
    
    create table FTPSites 
    (
      FTPSiteID int primary key, 
      UploadTypeID as 2 persisted,
      -- ...Other fields...
      foreign key (MasterTableID, UploadTypeID) references MasterTable(MasterTableID, UploadTypeID)
    )
    
    create table SFTPSites 
    (
      SFTPSiteID int primary key, 
      UploadTypeID as 3 persisted,
      -- ...Other fields...
      foreign key (MasterTableID, UploadTypeID) references MasterTable(MasterTableID, UploadTypeID)
    )
    

    Each of these type-specific tables includes a dual-key foreign key to the master table on the MasterTableID and the UploadTypeID (this is how you get your referential integrity), and each includes a computed-column for the UploadTypeID that reflects the specific type of upload stored in that table. Each of these computed columns will force any new records inserted into these type-specific tables to be created with a specific UploadTypeID, therefore locking the tables to a specific upload type.

    The beauty of this design is that it gives you database-driven referential constraints that meets all of your data integrity requirements without a lot of nulls. You can see the above posted article for detailed examples of how this schema prevents data integrity problems during inserts, deletes, etc. if you want to go deeper.

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

Sidebar

Related Questions

The best way to explain my problem is by a example. I have a
The best way of describing this is I have a table of people with
What is the best way to translate css so that it works in a
I was wondering what the best approach would be to the following problem. Say
I'm retrieving a group of customers and orders from sql, what's the best way
My question is about the best way to translate the email activation template of
been google'ing for a while how is the best way to translate with google
What is the best/correct way to translate for example a product description that is
Possible Duplicate: What’s the best way to find the inverse of datetime.isocalendar()? I have
I have the following problem to solve: Currently we have a metadata tree of

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.