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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:26:58+00:00 2026-05-10T22:26:58+00:00

I have an unusual situation to model in a MS SQL Server database: the

  • 0

I have an unusual situation to model in a MS SQL Server database: the primary key of a table is a multi-segment ‘natural’ key composed of 5 foreign keys (of fixed sizes).

I’d like to be able to define a user-defined data type to implement the data structure based on a CHAR(8) primitive in such a way that the elements are addressable as individual fields.

For example (in bad pseudocode):

UDT seggy (     seg1 char(2),     seg2 char(1),     seg3 char(1),     seg4 char(2),     seg5 char(2) )  create table yotable (     pkfield seggy NOT NULL,     etc varchar(14),   --whatever etc. ) with pkfield as the primary key, and also with seg1 as a foreign key to tableseg1, and also with seg2 as a foreign key to tableseg2, and so on 

and then be able to do things like this:

insert into yotable (pkfield, etc) values ('abcdefgh','whatever') select * from yotable where seg2 = 'c' insert into yotable (seg1,seg2,seg3,seg4,seg5,etc)     values ('ab','c','d','ef','gh', 'whatever') 

So far all I’ve found is this CodeProject article which does not go far enough or provide links for further info, and this rudimentary MSDN link.

Apparently my google-fu is weak tonight, any links/hints greatly appreciated!

Alternate title: how to simulate ‘overlay’ fields in SQL SERVER?

MS SQL SERVER 2005 or later assumed/preferred.

  • 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. 2026-05-10T22:26:58+00:00Added an answer on May 10, 2026 at 10:26 pm

    You can define a CLR UDT that has the structure you want, but (1) you won’t be able to keep the foreign keys (foreign keys have to be at the column level, not a field in a UDT in a column), and (2) it isn’t trivial to implement a CLR UDT (at least compared to what is in your pseudocode). Plus, from your description, it sounds like they really are separate columns semantically, and what you’re looking for is just a shortcut for convenience; IMO a UDT probably isn’t the best approach in that scenario anyway.

    I would suggest keeping the separate columns, but create either a view that has a column that concatenates the fields together, or a computed column in the table that does the same. This will permit searching using either the combined or separate notation. You can then use an INSTEAD OF trigger to decompose an insert/update on the combined column into the component parts.

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

Sidebar

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Yes, basically you're using the tools wrong. xgettext extracts the… May 11, 2026 at 1:03 pm
  • added an answer reinterpret_cast May 11, 2026 at 1:03 pm
  • added an answer First, from a technical perspective you should be asking the… May 11, 2026 at 1:03 pm

Related Questions

I have a bit of an unusual question. I'm running an old DOS game
I have an absolutely positioned div containing several children, one of which is a
I have an array in Perl: my @my_array = (one,two,three,two,three); How do I remove
I have an images folder with a png in it. I would like to
I've got an unusual situation: I'm using a Linux system in an embedded situation
I have an unusual idea to use git as a backup system. So let's
I have an array of dates in a one week range stored in an

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.