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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:22:09+00:00 2026-05-22T14:22:09+00:00

I’ve created a few table types in my database to be used as stored

  • 0

I’ve created a few table types in my database to be used as stored procedure parameters. These correspond to real database tables, so if they’re out of sync there’ll be a problem. I’d like to add a unit test that looks at the two and fails if they are different, but I’m not sure where to start.

I don’t know if there’s a recommended way to do this – I was going to try to somehow pull out the column information, loop through it and fail the test if they’re different, but it seems a bit fiddly.

Is there a better way?

  • 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-22T14:22:10+00:00Added an answer on May 22, 2026 at 2:22 pm

    For SQL Server 2008, take a look at the sys.tables, sys.table_types and sys.columns system tables.

    In one of my databases I have a table type called candidateRoutes and a physical (real) table called RouteArea

    The following two queries:

    select sys.columns.* from sys.table_types join sys.columns on sys.columns.object_id = sys.table_types.type_table_object_id where sys.table_types.name = 'candidateRoutes'
    select sys.columns.* from sys.tables join sys.columns on sys.columns.object_id = sys.tables.object_id where sys.tables.name = 'RouteArea'
    

    return:

    object_id  name     column_id  system_type_id  user_type_id  max_length  precision  scale  collation_name  is_nullable  is_ansi_padded    is_rowguidcol  is_identity  is_computed  is_filestream  is_replicated  is_non_sql_subscribed  is_merge_published  is_dts_replicated  is_xml_document  xml_collection_id  default_object_id  rule_object_id  is_sparse  is_column_set
    215671816  RouteId  1           56              56            4          10         0      NULL            0            0                 0              0            0            0              0              0                      0                   0                  0                0                  0                  0               0          0
    215671816  Area     2          240             130           -1           0         0      NULL            0            0                 0              0            0            0              0              0                      0                   0                  0                0                  0                  0               0          0
    

    and

    object_id   name       column_id  system_type_id  user_type_id  max_length  precision  scale  collation_name  is_nullable  is_ansi_padded  is_rowguidcol  is_identity  is_computed  is_filestream  is_replicated  is_non_sql_subscribed  is_merge_published  is_dts_replicated  is_xml_document  xml_collection_id  default_object_id  rule_object_id  is_sparse  is_column_set
    1675153013  RouteId    1          127             127            8          19         0      NULL            0            0               0              0            0            0              0              0                      0                   0                  0                0                  0                  0               0          0
    1675153013  ValidFrom  2           61              61            8          23         3      NULL            0            0               0              0            0            0              0              0                      0                   0                  0                0                  0                  0               0          0
    1675153013  ValidTo    3           61              61            8          23         3      NULL            1            0               0              0            0            0              0              0                      0                   0                  0                0                  0                  0               0          0
    1675153013  Line       4          240             130           -1           0         0      NULL            0            0               0              0            0            0              0              0                      0                   0                  0                0                  0                  0               0          0
    1675153013  Area       5          240             130           -1           0         0      NULL            1            0               0              0            0            0              0              0                      0                   0                  0                0                  0                  0               0          0
    

    so you could perhaps do something like this:

    with
        TableType as
            (select name, user_type_id, max_length, precision from sys.columns where object_id = (select type_table_object_id from sys.table_types where name = 'candidateRoutes')),
        PhysicalTable as
            (select name, user_type_id, max_length, precision from sys.columns where object_id = (select object_id from sys.tables where name = 'RouteArea'))
        select * from TableType full join PhysicalTable
            on TableType.name = PhysicalTable.name
        where TableType.name is null
           or PhysicalTable.name is null
           or TableType.user_type_id <> PhysicalTable.user_type_id
           or TableType.max_length   <> PhysicalTable.max_length
           or TableType.precision    <> PhysicalTable.precision
    

    but including scale, collation_name, is_nullable, etc., to find all columns that do not match. In my case, I get:

    name     user_type_id  max_length  precision  name       user_type_id  max_length  precision
    RouteId  56            4           10         RouteId    127           8           19
    NULL     NULL          NULL        NULL       ValidFrom  61            8           23
    NULL     NULL          NULL        NULL       ValidTo    61            8           23
    NULL     NULL          NULL        NULL       Line       130           -1          0
    

    If no rows are returned, the type and the table are the same.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.