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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:06:50+00:00 2026-05-11T01:06:50+00:00

I’ve been trying to come up with a good design pattern for mapping data

  • 0

I’ve been trying to come up with a good design pattern for mapping data contained in relational databases to the business objects I’ve created but I keep hitting a wall.

Consider the following tables:

TYPE: typeid, description USER: userid, username, usertypeid->TYPE.typeid, imageid->IMAGE.imageid IMAGE: imageid, location, imagetypeid->TYPE.typeid 

I would like to gather all the information regarding a specific user. Creating a query for this isn’t too difficult.

SELECT u.*, ut.*, i.*, it.* FROM user u INNER JOIN type ut ON ut.typeid = u.usertypeid INNER JOIN image i ON i.imageid = u.imageid INNER JOIN type it ON it.typeid = i.imagetypeid WHERE u.userid = @userid 

The problem is that the field names collide and then I’m forced to alias every single field which gets out of hand very quickly.

Does anyone have a decent design pattern for this kind of thing?

I’ve thought about retrieving multiple results from a single stored procedure and then using a dataset to iterate through each one but I’m worried that some performance issues might bite me in the butt later. For example instead of the above query something like:

SELECT u.*, t.* FROM user u INNER JOIN type t ON t.typeid = u.usertypeid WHERE u.userid = @userid; SELECT i.*, t.* FROM image i INNER JOIN type t ON t.typeid = i.imagetypeid INNER JOIN user u ON u.imageid = i.imageid WHERE u.userid = @userid; 

Does that seem like a decent solution? Can anyone foresee any issues with this approach?

  • 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-11T01:06:50+00:00Added an answer on May 11, 2026 at 1:06 am

    Never use the SQL * wildcard in production code. Always spell out all the columns you want to retrieve.

    Then aliasing some of them doesn’t seem like such a huge amount of extra work.


    Re your comment asking for background and reasoning:

    • Sometimes you don’t really need every column from all tables, and fetching them can be needlessly costly (especially for large strings and blobs). There is no SQL syntax for "all columns except the following exceptions."

    • You can’t alias columns that you fetch using the wildcard. Once you need to alias any of the columns, you need to expand the wildcard to list all the columns explicitly.

    • If the table structure changes, e.g. columns are renamed, reordered, dropped, or added, then the wildcard fetches them all, by position as defined in the tables. This may seem like a convenience, but not when your application depends on columns being in the result set by a given name or in a given position. You can get mysterious bugs where your application displays columns in the wrong order (if referencing columns by position), or shows them as blank (if referencing columns by name).

      However, if the SQL query names columns explicitly, you can employ the "Fail Early" principle. This helps debugging, because it leads you directly to the SQL query that needs to be edited to account for the schema change.

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

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • 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
  • Editorial Team
    Editorial Team added an answer Trying this from inside a script running under apache will… May 11, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer This error means that your code corrupted internal memory manager's… May 11, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer I use Stanza to convert Microsoft doc files to AZW,… May 11, 2026 at 11:45 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.