Create Table using Xml Files

Geoffrey SOUQUIÈRE 51 Reputation points
2022-05-31T14:04:55.583+00:00

Hi There,

Hope you are getting well.

I was wondering, is there a way to use xml file as input to create table automatically.

Here is the schema, we got all information we need to create tables and columns. Schema comes from an url Odata/$metadata

207162-image.png

Thx,
Have a nice day

Azure SQL Database
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. GeethaThatipatri-MSFT 29,542 Reputation points Microsoft Employee Moderator
    2022-06-01T05:52:43.52+00:00

    Hi, @Geoffrey SOUQUIÈRE Thanks for posting your question in the Microsoft Q&A forum.
    Please find this blog which helps you to convert XML to table https://www.c-sharpcorner.com/blogs/sql-query-to-convert-xml-to-table

    Please let me know if you need any additional information.

    Regards
    Geetha

    1 person found this answer helpful.

  2. Geoffrey SOUQUIÈRE 51 Reputation points
    2022-06-02T07:16:37.31+00:00

    Hi @GeethaThatipatri-MSFT ,

    Thx for testing the code.

    My goal is to create table without data regarding xml schema.

    I suppose there is not such a thing on SQL... Unfortunate

    If i take the example below :

    XML (Input)

    <EntityType Name="BuyerParty">
    <Key>
    <PropertyRef Name="ObjectID"/>
    </Key>
    <Property Name="ObjectID" Type="Edm.String" Nullable="false" MaxLength="70" FixedLength="true" sap:creatable="false" sap:updatable="false" sap:filterable="true"/>
    <Property Name="ParentObjectID" Type="Edm.String" Nullable="true" MaxLength="70" FixedLength="true" sap:creatable="true" sap:updatable="false" sap:filterable="true"/>
    <Property Name="PartyID" Type="Edm.String" Nullable="true" MaxLength="60" FixedLength="true" sap:creatable="false" sap:updatable="false" sap:filterable="true"/>
    <NavigationProperty Name="CustomerInvoice" Relationship="cust.CustomerInvoice_BuyerParty" FromRole="BuyerParty" ToRole="CustomerInvoice"/>
    <NavigationProperty Name="BuyerPartyName" Relationship="cust.BuyerParty_BuyerPartyName" FromRole="BuyerParty" ToRole="BuyerPartyName"/>
    <NavigationProperty Name="BuyerPartyFormattedAddress" Relationship="cust.BuyerParty_BuyerPartyFormattedAddress" FromRole="BuyerParty" ToRole="BuyerPartyFormattedAddress"/>
    </EntityType>

    SQL (Output)

    Create table BuyerParty207812-image.png

    I didn't write the FK associate to BuyerPartyName & BuyerPartyFormattedAddress.

    Have a nice day

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.