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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:34:59+00:00 2026-06-04T05:34:59+00:00

I am working with a legacy database that has a large number of user-defined

  • 0

I am working with a legacy database that has a large number of user-defined SQL types. I am writing a method in .NET in which I am defining parameters in the SqlParameter object. I need the underlying SQL types for the user defined types in order to properly define the parameters as I create them dynamically at runtime.

To do this I created this procedure:

(@typename sysname)  

AS  

SET NOCOUNT ON  

SELECT distinct
st.name as UserType,
t.precision, t.max_length,
bt.name as BaseType
FROM
dbo.syscolumns c
INNER JOIN dbo.systypes st ON st.xusertype = c.xusertype
INNER JOIN dbo.systypes bt ON bt.xusertype = c.xtype
inner join sys.types t on st.name = t.name
WHERE
st.name = 'bVendor'

I am wondering if this is the best way to go about getting the underlying base type for a user defined type?

  • 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-06-04T05:35:00+00:00Added an answer on June 4, 2026 at 5:35 am

    You shouldn’t be using systypes or syscolumns – these are backward compatibility views, and sys.types and sys.columns are highly preferred unless you are trying to write code that works on SQL Server 2000+ (which I don’t recommend either).

    To get the information about a type you already know the name of:

    SELECT name, precision, scale, max_length
      FROM sys.types AS t
      WHERE name = 'bVendor';
    

    To get the information for all the user-defined types in a database:

    SELECT name, precision, scale, max_length
      FROM sys.types AS t
      WHERE is_user_defined = 1;
    

    To get the information about all the types (system and user-defined) for a specific table:

    UPDATE to include the base type:

    SELECT 
      [column] = c.name, 
      [base type] = COALESCE(bt.name, t.name),
      [defined type] = t.name, 
      t.precision, 
      t.scale, 
      t.max_length
    FROM sys.columns AS c
    INNER JOIN sys.types AS t
    ON c.system_type_id = t.system_type_id
    AND c.user_type_id = t.user_type_id
    LEFT OUTER JOIN sys.types AS bt
    ON t.is_user_defined = 1
    AND bt.is_user_defined = 0
    AND t.system_type_id = bt.system_type_id
    AND t.user_type_id <> bt.user_type_id
    WHERE c.object_id = OBJECT_ID('dbo.your_table_name');
    

    Note that this will return two rows if you use alias types (e.g. CREATE TYPE blat FROM nvarchar(32);). If you really must use those (I recommend against them, also), then change the join clause to:

    ON t.is_user_defined = 1
    AND bt.is_user_defined = 0
    AND t.system_type_id = bt.system_type_id
    AND bt.user_type_id = bt.system_type_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with a legacy SQL Server database which has a core table with
I am working on legacy code which has a number of defunct database calls
I'm working on a legacy database table that has a phone no. field but
I am working with a legacy database that has a table to store up
We are working with a legacy database that uses SQL server uniqueidentifier columns for
I am working with a legacy database that stores blank values as a single
I am working with a database from a legacy app which stores 24 floating
I'm working on a legacy system that has uses stored procs, business objects and
The project I'm working on has a legacy database with lots of information in
I'm working with a legacy database which doesn't use great conventions, but I'm unable

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.