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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:14:48+00:00 2026-06-13T00:14:48+00:00

I found this tsql query that shows the xml schema of a table and

  • 0

I found this tsql query that shows the xml schema of a table and it works very well.

SELECT * FROM TableA
FOR XML AUTO, XMLSCHEMA

I am now attempting to show the relationship between tables via this query. I am not sure if this is possible. I have mocked up several test tables and I have not had any luck. Basically, I am creating a one to many relationship between tableA and tableB, then in the xml schema it would show tableA as a parent and tableB would be a child within the schema.

This is what I have been running. :

SELECT * FROM TableA,
dbo.TableB 
FOR XML AUTO, XMLSCHEMA

Here is an example xml schema file that I am getting from the above query.

<xsd:schema targetNamespace="urn:schemas-microsoft-com:sql:SqlRowSet7" xmlns:schema="urn:schemas-microsoft-com:sql:SqlRowSet7" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes" elementFormDefault="qualified">
  <xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes" schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd" />
  <xsd:element name="TableA">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="columnA" type="sqltypes:int" />
        <xsd:element name="columnB">
          <xsd:simpleType>
            <xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="BinarySort">
              <xsd:maxLength value="50" />
            </xsd:restriction>
          </xsd:simpleType>
        </xsd:element>
        <xsd:element ref="schema:dbo.tylersTestTable2" minOccurs="0" maxOccurs="unbounded" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="TableB">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="columnA" type="sqltypes:int" />
        <xsd:element name="columnB">
          <xsd:simpleType>
            <xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="BinarySort">
              <xsd:maxLength value="50" />
            </xsd:restriction>
          </xsd:simpleType>
        </xsd:element>
        <xsd:element name="fkToTableA" type="sqltypes:int" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

As you can see it is displaying the tables as equal levels within the schema and not really displaying a parent child relationship.
I am kind of at a loss here as I am no dba, but I have to do this for a ton of tables and I don’t want to have to write them all by hand.

Any ideas on this one?

  • 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-13T00:14:49+00:00Added an answer on June 13, 2026 at 12:14 am

    Tables in TSQL do not have true parent-child relationships. Each table is at the same level and foreign key relationships may cause constraints on data in one or both tables. Logically, one table may be a parent and one a child, but in no way does that mean they are a physical hierarchy. You may be able to generate XML like you’re asking for with a modeling tool like ERwin that interprets the physical model into a logical one but TSQL really only sees the physical model.

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

Sidebar

Related Questions

I have a tsql snippet similar to this: select p.Make, count(p.Make) as _count from
found this little code snippet that seems to do what i want, but im
Found this question that explained a way to communicate between layers. However there is
I sometimes see in a select query a where-clause like this : where col_name
Found this method of having DIV as custom google maps infoWindow. It works, but
I am looking into doing some efficient paging and found this link that says
Take the tsql query below: DECLARE @table TABLE(data VARCHAR(20)) INSERT INTO @table VALUES ('not
I have a query in Delphi using DBExpress TSQLQuery that looks like so ActiveSQL.sql.add('SELECT
I've got a query that I've just found in the database that is failing
Found this while reading the Neo4j manual, specifically here , I found the sentence:

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.