Foriegn key error while running liquibase - database

I am working on a modular architecture project where each module has there own liquibase. Let assume I have two module name module-a and module-b. Module-b liquibase have the reference of the column which defined in module-a liquibase. While inserting data through liquibase of module-b getting the foreign key exception while foreign key data is defined in liquibase of module-a.
Below is description of module-a liquibase:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet author="mukesh" id="1227303685425-4">
<createTable tableName="concept">
<column autoIncrement="true" name="concept_id" type="int">
<constraints nullable="false" primaryKey="true"/>
</column>
<column defaultValueBoolean="false" name="retired" type="BOOLEAN">
<constraints nullable="false"/>
</column>
<column name="short_name" type="varchar(255)"/>
<column name="description" type="text"/>
<column name="form_text" type="text"/>
<column defaultValueNumeric="0" name="datatype_id" type="int">
<constraints nullable="false"/>
</column>
<column defaultValueNumeric="0" name="class_id" type="int">
<constraints nullable="false"/>
</column>
<column defaultValueBoolean="false" name="is_set" type="BOOLEAN">
<constraints nullable="false"/>
</column>
<column defaultValueNumeric="0" name="creator" type="int">
<constraints nullable="false"/>
</column>
<column name="date_created" type="DATETIME">
<constraints nullable="false"/>
</column>
<column name="version" type="varchar(50)"/>
<column name="changed_by" type="int"/>
<column name="date_changed" type="DATETIME"/>
<column name="retired_by" type="int"/>
<column name="date_retired" type="DATETIME"/>
<column name="retire_reason" type="varchar(255)"/>
<column name="uuid" type="char(38)" />
</createTable>
<createTable tableName="concept_answer">
<column autoIncrement="true" name="concept_answer_id" type="int">
<constraints nullable="false" primaryKey="true"/>
</column>
<column defaultValueNumeric="0" name="concept_id" type="int">
<constraints nullable="false"/>
</column>
<column name="answer_concept" type="int"/>
<column name="answer_drug" type="int"/>
<column defaultValueNumeric="0" name="creator" type="int">
<constraints nullable="false"/>
</column>
<column name="date_created" type="DATETIME">
<constraints nullable="false"/>
</column>
<column name="sort_weight" type="double precision"></column>
<column name="uuid" type="char(38)" />
</createTable>
<modifySql dbms="mssql">
<replace replace="CHAR(38)" with="UNIQUEIDENTIFIER NOT NULL DEFAULT NEWSEQUENTIALID()" />
</modifySql>
<insert tableName="concept">
<column name="concept_id" valueNumeric="51"/>
<column name="retired" valueBoolean="true"/>
<column name="short_name" value=""/>
<column name="description" value=""/>
<column name="form_text"/>
<column name="datatype_id" valueNumeric="4"/>
<column name="class_id" valueNumeric="4"/>
<column name="is_set" valueBoolean="false"/>
<column name="creator" valueNumeric="1"/>
<column name="date_created" valueDate="2004-01-01"/>
<column name="version" value=""/>
<column name="changed_by"/>
<column name="date_changed"/>
<column name="retired_by"/>
<column name="date_retired"/>
<column name="retire_reason"/>
</insert>
</changeSet>
</databaseChangeLog>
Module-b liquibase description:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet author="mukesh" id="1227303685425-4">
<insert tableName="concept_answer">
<column name="concept_answer_id" valueNumeric="1"/>
<column name="concept_id" valueNumeric="51"/>
<column name="answer_concept" valueNumeric="1115"/>
<column name="answer_drug"/>
<column name="creator" valueNumeric="1"/>
<column name="date_created" valueDate="2005-01-26"/>
</insert>
</changeSet>
</databaseChangeLog>
Please, someone help me to solve this issue.

Related

MS SQL: XML translater

I want to extract the itemnumber from the XML data to columns.
However in the XML file there is more than 1 value (itemnumber) per row.
(there could be about 100 itemnumbers per row)
My query works good but its too slow due to the amount of sub-queries I'd have to make to extract all the data out of the XML
The sub-query looks like this
SELECT RIGHT(LEFT(Cast(x.data AS XML).value ('(table/id/text())[1]','varchar(100)'),37),36) AS id,
Cast(x.data AS XML).value ('(//column[#name="Artikelen"]/#value)[9]','VARCHAR(255)') AS 'item',
Cast(x.data AS XML).value ('(//column[#name="Batchnummer"]/#value)[9]','VARCHAR(255)') AS Batch,
Cast(x.data AS XML).value('(//column[#name="Aantal"]/#value)[9]','INT') AS Aantal
FROM synergy..xmldata x (nolock)
WHERE Cast(x.data AS XML).value ('(//column[#name="Artikelen"]/#value)[9]','VARCHAR(255)') IS NOT NULL
Now this works good but I have to use Union all about 100 times to extract all the data
Is there an easier way to do this?
This is what the full query looks like (FYI I used statement Union all 3 times, if I want it to work I have to copy/paste that 100 times and change the value amount /#value)[xxxx] )
SELECT XMLDATA.id ,
XMLDATA.item ,
XMLDATA.batchnummer ,
XMLDATA.aantal ,
y.freetextfield_02
FROM (
SELECT RIGHT(LEFT(Cast(x.data AS XML).value ('(table/id/text())[1]','varchar(100)'),37),36) AS id,
Cast(x.data AS XML).value ('(//column[#name="Artikelen"]/#value)[1]','VARCHAR(255)') AS 'item',
Cast(x.data AS XML).value ('(//column[#name="Batchnummer"]/#value)[1]','VARCHAR(255)') AS Batch,
Cast(x.data AS XML).value('(//column[#name="Aantal"]/#value)[1]','INT') AS Aantal
FROM synergy..xmldata x (nolock)
WHERE Cast(x.data AS XML).value ('(//column[#name="Artikelen"]/#value)[1]','VARCHAR(255)') IS NOT NULL
UNION ALL
SELECT RIGHT(LEFT(Cast(x.data AS XML).value ('(table/id/text())[1]','varchar(100)'),37),36) AS id,
Cast(x.data AS XML).value ('(//column[#name="Artikelen"]/#value)[2]','VARCHAR(255)') AS 'item',
Cast(x.data AS XML).value ('(//column[#name="Batchnummer"]/#value)[2]','VARCHAR(255)') AS Batch,
Cast(x.data AS XML).value('(//column[#name="Aantal"]/#value)[2]','INT') AS Aantal
FROM synergy..xmldata x (nolock)
WHERE Cast(x.data AS XML).value ('(//column[#name="Artikelen"]/#value)[2]','VARCHAR(255)') IS NOT NULL
UNION ALL
SELECT RIGHT(LEFT(Cast(x.data AS XML).value ('(table/id/text())[1]','varchar(100)'),37),36) AS id,
Cast(x.data AS XML).value ('(//column[#name="Artikelen"]/#value)[3]','VARCHAR(255)') AS 'item',
Cast(x.data AS XML).value ('(//column[#name="Batchnummer"]/#value)[3]','VARCHAR(255)') AS Batch,
Cast(x.data AS XML).value('(//column[#name="Aantal"]/#value)[3]','INT') AS Aantal
FROM synergy..xmldata x (nolock)
WHERE Cast(x.data AS XML).value ('(//column[#name="Artikelen"]/#value)[3]','VARCHAR(255)') IS NOT NULL
) XMLDATA
LEFT JOIN synergy..absences y (nolock)
ON y.id = XMLDATA.id
WHERE y. freetextfield_02 IS NOT NULL
AND type IN ('126',
'129')
this is what the XML looks like:
<table>
<id>{351CE2EE-59E8-43B0-B95B-81A24A2C037E}</id>
<rows>
<row>
<columns>
<column name="Artikelen" value="101445.A.FF" type="System.String" />
<column name="Batchnummer" value="PR1900002366" type="System.String" />
<column name="Aantal" value="1" type="System.Int32" />
<column name="Opmerkingen" value="retour" type="System.String" />
<column name="Magazijn" value="" type="System.String" />
<column name="Reden" value="" type="System.String" />
<column name="DefaultKey" value="2" type="System.Int32" />
</columns>
</row>
<row>
<columns>
<column name="Artikelen" value="101445.A.FF" type="System.String" />
<column name="Batchnummer" value="PR1900002366" type="System.String" />
<column name="Aantal" value="1" type="System.Int32" />
<column name="Opmerkingen" value="retour" type="System.String" />
<column name="Magazijn" value="" type="System.String" />
<column name="Reden" value="" type="System.String" />
<column name="DefaultKey" value="3" type="System.Int32" />
</columns>
</row>
<row>
<columns>
<column name="Artikelen" value="101445.A.FF" type="System.String" />
<column name="Batchnummer" value="PR1900002366" type="System.String" />
<column name="Aantal" value="1" type="System.Int32" />
<column name="Opmerkingen" value="retour" type="System.String" />
<column name="Magazijn" value="" type="System.String" />
<column name="Reden" value="" type="System.String" />
<column name="DefaultKey" value="4" type="System.Int32" />
</columns>
</row>
<row>
<columns>
<column name="Artikelen" value="101445.A.FF" type="System.String" />
<column name="Batchnummer" value="PR1900002366" type="System.String" />
<column name="Aantal" value="1" type="System.Int32" />
<column name="Opmerkingen" value="retour" type="System.String" />
<column name="Magazijn" value="" type="System.String" />
<column name="Reden" value="" type="System.String" />
<column name="DefaultKey" value="5" type="System.Int32" />
</columns>
</row>
<row>
<columns>
<column name="Artikelen" value="3.46331132.NL" type="System.String" />
<column name="Batchnummer" value="190259" type="System.String" />
<column name="Aantal" value="10" type="System.Int32" />
<column name="Opmerkingen" value="retour" type="System.String" />
<column name="Magazijn" value="" type="System.String" />
<column name="Reden" value="" type="System.String" />
<column name="DefaultKey" value="14" type="System.Int32" />
</columns>
</row>
</rows>
<key>DefaultKey</key>
<total>0</total>
<AddOnKey>0</AddOnKey>
<data />
<parameters />
</table>
This is what the dataset TABLE looks like i'm extracting the xml from the column Data
DATASET XML IMAGE
You need to use nodes to create a row in the dataset for each columns node. Then you can treat it like a data set:
DECLARE #XML xml = '<table>
<id>{351CE2EE-59E8-43B0-B95B-81A24A2C037E}</id>
<rows>
<row>
<columns>
<column name="Artikelen" value="101445.A.FF" type="System.String" />
<column name="Batchnummer" value="PR1900002366" type="System.String" />
<column name="Aantal" value="1" type="System.Int32" />
<column name="Opmerkingen" value="retour" type="System.String" />
<column name="Magazijn" value="" type="System.String" />
<column name="Reden" value="" type="System.String" />
<column name="DefaultKey" value="2" type="System.Int32" />
</columns>
</row>
<row>
<columns>
<column name="Artikelen" value="101445.A.FF" type="System.String" />
<column name="Batchnummer" value="PR1900002366" type="System.String" />
<column name="Aantal" value="1" type="System.Int32" />
<column name="Opmerkingen" value="retour" type="System.String" />
<column name="Magazijn" value="" type="System.String" />
<column name="Reden" value="" type="System.String" />
<column name="DefaultKey" value="3" type="System.Int32" />
</columns>
</row>
<row>
<columns>
<column name="Artikelen" value="101445.A.FF" type="System.String" />
<column name="Batchnummer" value="PR1900002366" type="System.String" />
<column name="Aantal" value="1" type="System.Int32" />
<column name="Opmerkingen" value="retour" type="System.String" />
<column name="Magazijn" value="" type="System.String" />
<column name="Reden" value="" type="System.String" />
<column name="DefaultKey" value="4" type="System.Int32" />
</columns>
</row>
<row>
<columns>
<column name="Artikelen" value="101445.A.FF" type="System.String" />
<column name="Batchnummer" value="PR1900002366" type="System.String" />
<column name="Aantal" value="1" type="System.Int32" />
<column name="Opmerkingen" value="retour" type="System.String" />
<column name="Magazijn" value="" type="System.String" />
<column name="Reden" value="" type="System.String" />
<column name="DefaultKey" value="5" type="System.Int32" />
</columns>
</row>
<row>
<columns>
<column name="Artikelen" value="3.46331132.NL" type="System.String" />
<column name="Batchnummer" value="190259" type="System.String" />
<column name="Aantal" value="10" type="System.Int32" />
<column name="Opmerkingen" value="retour" type="System.String" />
<column name="Magazijn" value="" type="System.String" />
<column name="Reden" value="" type="System.String" />
<column name="DefaultKey" value="14" type="System.Int32" />
</columns>
</row>
</rows>
<key>DefaultKey</key>
<total>0</total>
<AddOnKey>0</AddOnKey>
<data />
<parameters />
</table>';
SELECT V.X.value('(/table/id/text())[1]','varchar(255)') AS id,
r.c.value('(./column[#name="Artikelen"]/#value)[1]', 'varchar(255)') AS item,
r.c.value('(./column[#name="Batchnummer"]/#value)[1]', 'varchar(255)') AS Batch,
r.c.value('(./column[#name="Aantal"]/#value)[1]', 'varchar(255)') AS Aantal
FROM (VALUES (#XML)) V (X)
CROSS APPLY V.X.nodes('table/rows/row/columns') r(c);

Cannot check tables, views in update wizard when updating model from database at Visual Studio 2017

I have a Microsoft SQL Server database connected to an Entity Framework Web API project. I run SSMS & VS 2017.
I erased some column in the model and I want to re-create it with updating from the database. When I try updating model from DB option on the edmx file, there is an update wizard.
The update wizard doesn't allow me to check and table or view in the wizard. It also doesn't add the column from the database to model.
I also have errors as follows (that maybe will disappear when the column will be added to the model):
Error 3023: Problem in mapping fragments starting at line 309:Column GamesScores.GameDateCreation in table GamesScores must be mapped: It has no default value and is not nullable.
01-Data Access Layer C:\projects\webApi\memory match game\Memory Match Game\01-Data Access Layer\MemoryMatch.edmx 310
Error CS0006 Metadata file 'C:\projects\webApi\memory match game\Memory Match Game\03-Business Logic Layer\bin\Debug\03-Business Logic Layer.dll' could not be found
04- Web Api C:\projects\webApi\memory match game\Memory Match Game\04- Web
Api\CSC 1 Active
Here is the mapping of the tables
And here is the EDMX code in a HTML view:
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="3.0" xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="MemoryMatchModel.Store" Provider="System.Data.SqlClient" ProviderManifestToken="2012" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
<EntityType Name="ContactMessages">
<Key>
<PropertyRef Name="MessageID" />
</Key>
<Property Name="MessageID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
<Property Name="MessageTimeStamp" Type="datetime" Nullable="false" />
<Property Name="Phone" Type="nvarchar" MaxLength="50" />
<Property Name="Email" Type="nvarchar" MaxLength="50" />
<Property Name="MessageText" Type="nvarchar" MaxLength="200" Nullable="false" />
</EntityType>
<EntityType Name="Feedbacks">
<Key>
<PropertyRef Name="FeedbackID" />
</Key>
<Property Name="FeedbackID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
<Property Name="UserID" Type="int" Nullable="false" />
<Property Name="FeedbackTimeStamp" Type="datetime" Nullable="false" />
<Property Name="FeedbackText" Type="nvarchar" MaxLength="250" Nullable="false" />
</EntityType>
<EntityType Name="GamesScores">
<Key>
<PropertyRef Name="GameScoreID" />
</Key>
<Property Name="GameScoreID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
<Property Name="UserID" Type="int" Nullable="false" />
<Property Name="GameDateCreation" Type="datetime" Nullable="false" />
<Property Name="GameDuration" Type="time" Precision="7" Nullable="false" />
<Property Name="GameSteps" Type="int" Nullable="false" />
</EntityType>
<EntityType Name="Images">
<Key>
<PropertyRef Name="ImageID" />
</Key>
<Property Name="ImageID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
<Property Name="ImageName" Type="nvarchar" MaxLength="256" Nullable="false" />
</EntityType>
<EntityType Name="sysdiagrams">
<Key>
<PropertyRef Name="diagram_id" />
</Key>
<Property Name="name" Type="nvarchar" MaxLength="128" Nullable="false" />
<Property Name="principal_id" Type="int" Nullable="false" />
<Property Name="diagram_id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
<Property Name="version" Type="int" />
<Property Name="definition" Type="varbinary(max)" />
</EntityType>
<EntityType Name="Users">
<Key>
<PropertyRef Name="UserID" />
</Key>
<Property Name="UserID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
<Property Name="FullName" Type="nvarchar" MaxLength="50" Nullable="false" />
<Property Name="UserName" Type="nvarchar" MaxLength="50" Nullable="false" />
<Property Name="Password" Type="nvarchar" MaxLength="50" Nullable="false" />
<Property Name="Email" Type="nvarchar" MaxLength="50" />
<Property Name="Birthdate" Type="date" />
</EntityType>
<Association Name="FK_Feedbacks_Users">
<End Role="Users" Type="Self.Users" Multiplicity="1" />
<End Role="Feedbacks" Type="Self.Feedbacks" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="Users">
<PropertyRef Name="UserID" />
</Principal>
<Dependent Role="Feedbacks">
<PropertyRef Name="UserID" />
</Dependent>
</ReferentialConstraint>
</Association>
<Association Name="FK_GamesScores_Users">
<End Role="Users" Type="Self.Users" Multiplicity="1" />
<End Role="GamesScores" Type="Self.GamesScores" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="Users">
<PropertyRef Name="UserID" />
</Principal>
<Dependent Role="GamesScores">
<PropertyRef Name="UserID" />
</Dependent>
</ReferentialConstraint>
</Association>
<Function Name="fn_diagramobjects" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo" ReturnType="int" />
<Function Name="sp_alterdiagram" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
<Parameter Name="diagramname" Type="nvarchar" Mode="In" />
<Parameter Name="owner_id" Type="int" Mode="In" />
<Parameter Name="version" Type="int" Mode="In" />
<Parameter Name="definition" Type="varbinary(max)" Mode="In" />
</Function>
<Function Name="sp_creatediagram" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
<Parameter Name="diagramname" Type="nvarchar" Mode="In" />
<Parameter Name="owner_id" Type="int" Mode="In" />
<Parameter Name="version" Type="int" Mode="In" />
<Parameter Name="definition" Type="varbinary(max)" Mode="In" />
</Function>
<Function Name="sp_dropdiagram" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
<Parameter Name="diagramname" Type="nvarchar" Mode="In" />
<Parameter Name="owner_id" Type="int" Mode="In" />
</Function>
<Function Name="sp_helpdiagramdefinition" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
<Parameter Name="diagramname" Type="nvarchar" Mode="In" />
<Parameter Name="owner_id" Type="int" Mode="In" />
</Function>
<Function Name="sp_helpdiagrams" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
<Parameter Name="diagramname" Type="nvarchar" Mode="In" />
<Parameter Name="owner_id" Type="int" Mode="In" />
</Function>
<Function Name="sp_renamediagram" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
<Parameter Name="diagramname" Type="nvarchar" Mode="In" />
<Parameter Name="owner_id" Type="int" Mode="In" />
<Parameter Name="new_diagramname" Type="nvarchar" Mode="In" />
</Function>
<Function Name="sp_upgraddiagrams" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo" />
<EntityContainer Name="MemoryMatchModelStoreContainer">
<EntitySet Name="ContactMessages" EntityType="Self.ContactMessages" Schema="dbo" store:Type="Tables" />
<EntitySet Name="Feedbacks" EntityType="Self.Feedbacks" Schema="dbo" store:Type="Tables" />
<EntitySet Name="GamesScores" EntityType="Self.GamesScores" Schema="dbo" store:Type="Tables" />
<EntitySet Name="Images" EntityType="Self.Images" Schema="dbo" store:Type="Tables" />
<EntitySet Name="sysdiagrams" EntityType="Self.sysdiagrams" Schema="dbo" store:Type="Tables" />
<EntitySet Name="Users" EntityType="Self.Users" Schema="dbo" store:Type="Tables" />
<AssociationSet Name="FK_Feedbacks_Users" Association="Self.FK_Feedbacks_Users">
<End Role="Users" EntitySet="Users" />
<End Role="Feedbacks" EntitySet="Feedbacks" />
</AssociationSet>
<AssociationSet Name="FK_GamesScores_Users" Association="Self.FK_GamesScores_Users">
<End Role="Users" EntitySet="Users" />
<End Role="GamesScores" EntitySet="GamesScores" />
</AssociationSet>
</EntityContainer>
</Schema></edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schema Namespace="MemoryMatchModel" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityType Name="ContactMessage">
<Key>
<PropertyRef Name="MessageID" />
</Key>
<Property Name="MessageID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Name="MessageTimeStamp" Type="DateTime" Nullable="false" Precision="3" />
<Property Name="Phone" Type="String" MaxLength="50" FixedLength="false" Unicode="true" />
<Property Name="Email" Type="String" MaxLength="50" FixedLength="false" Unicode="true" />
<Property Name="MessageText" Type="String" MaxLength="200" FixedLength="false" Unicode="true" Nullable="false" />
</EntityType>
<EntityType Name="Feedback">
<Key>
<PropertyRef Name="FeedbackID" />
</Key>
<Property Name="FeedbackID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Name="UserID" Type="Int32" Nullable="false" />
<Property Name="FeedbackTimeStamp" Type="DateTime" Nullable="false" Precision="3" />
<Property Name="FeedbackText" Type="String" MaxLength="250" FixedLength="false" Unicode="true" Nullable="false" />
<NavigationProperty Name="User" Relationship="Self.FK_Feedbacks_Users" FromRole="Feedbacks" ToRole="Users" />
</EntityType>
<EntityType Name="GamesScore">
<Key>
<PropertyRef Name="GameScoreID" />
</Key>
<Property Name="GameScoreID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Name="UserID" Type="Int32" Nullable="false" />
<Property Name="GameSteps" Type="Int32" Nullable="false" />
<NavigationProperty Name="User" Relationship="Self.FK_GamesScores_Users" FromRole="GamesScores" ToRole="Users" />
<Property Name="GameDuration" Type="Time" Nullable="false" Precision="7" />
</EntityType>
<EntityType Name="Image">
<Key>
<PropertyRef Name="ImageID" />
</Key>
<Property Name="ImageID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Name="ImageName" Type="String" MaxLength="256" FixedLength="false" Unicode="true" Nullable="false" />
</EntityType>
<EntityType Name="sysdiagram">
<Key>
<PropertyRef Name="diagram_id" />
</Key>
<Property Name="name" Type="String" MaxLength="128" FixedLength="false" Unicode="true" Nullable="false" />
<Property Name="principal_id" Type="Int32" Nullable="false" />
<Property Name="diagram_id" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Name="version" Type="Int32" />
<Property Name="definition" Type="Binary" MaxLength="Max" FixedLength="false" />
</EntityType>
<EntityType Name="User">
<Key>
<PropertyRef Name="UserID" />
</Key>
<Property Name="UserID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Name="FullName" Type="String" MaxLength="50" FixedLength="false" Unicode="true" Nullable="false" />
<Property Name="UserName" Type="String" MaxLength="50" FixedLength="false" Unicode="true" Nullable="false" />
<Property Name="Password" Type="String" MaxLength="50" FixedLength="false" Unicode="true" Nullable="false" />
<Property Name="Email" Type="String" MaxLength="50" FixedLength="false" Unicode="true" />
<Property Name="Birthdate" Type="DateTime" Precision="0" />
<NavigationProperty Name="Feedbacks" Relationship="Self.FK_Feedbacks_Users" FromRole="Users" ToRole="Feedbacks" />
<NavigationProperty Name="GamesScores" Relationship="Self.FK_GamesScores_Users" FromRole="Users" ToRole="GamesScores" />
</EntityType>
<Association Name="FK_Feedbacks_Users">
<End Role="Users" Type="Self.User" Multiplicity="1" />
<End Role="Feedbacks" Type="Self.Feedback" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="Users">
<PropertyRef Name="UserID" />
</Principal>
<Dependent Role="Feedbacks">
<PropertyRef Name="UserID" />
</Dependent>
</ReferentialConstraint>
</Association>
<Association Name="FK_GamesScores_Users">
<End Role="Users" Type="Self.User" Multiplicity="1" />
<End Role="GamesScores" Type="Self.GamesScore" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="Users">
<PropertyRef Name="UserID" />
</Principal>
<Dependent Role="GamesScores">
<PropertyRef Name="UserID" />
</Dependent>
</ReferentialConstraint>
</Association>
<EntityContainer Name="MemoryMatchEntities" annotation:LazyLoadingEnabled="true">
<EntitySet Name="ContactMessages" EntityType="Self.ContactMessage" />
<EntitySet Name="Feedbacks" EntityType="Self.Feedback" />
<EntitySet Name="GamesScores" EntityType="Self.GamesScore" />
<EntitySet Name="Images" EntityType="Self.Image" />
<EntitySet Name="sysdiagrams" EntityType="Self.sysdiagram" />
<EntitySet Name="Users" EntityType="Self.User" />
<AssociationSet Name="FK_Feedbacks_Users" Association="Self.FK_Feedbacks_Users">
<End Role="Users" EntitySet="Users" />
<End Role="Feedbacks" EntitySet="Feedbacks" />
</AssociationSet>
<AssociationSet Name="FK_GamesScores_Users" Association="Self.FK_GamesScores_Users">
<End Role="Users" EntitySet="Users" />
<End Role="GamesScores" EntitySet="GamesScores" />
</AssociationSet>
<FunctionImport Name="sp_alterdiagram">
<Parameter Name="diagramname" Mode="In" Type="String" />
<Parameter Name="owner_id" Mode="In" Type="Int32" />
<Parameter Name="version" Mode="In" Type="Int32" />
<Parameter Name="definition" Mode="In" Type="Binary" />
</FunctionImport>
<FunctionImport Name="sp_creatediagram">
<Parameter Name="diagramname" Mode="In" Type="String" />
<Parameter Name="owner_id" Mode="In" Type="Int32" />
<Parameter Name="version" Mode="In" Type="Int32" />
<Parameter Name="definition" Mode="In" Type="Binary" />
</FunctionImport>
<FunctionImport Name="sp_dropdiagram">
<Parameter Name="diagramname" Mode="In" Type="String" />
<Parameter Name="owner_id" Mode="In" Type="Int32" />
</FunctionImport>
<FunctionImport Name="sp_helpdiagramdefinition" ReturnType="Collection(MemoryMatchModel.sp_helpdiagramdefinition_Result)">
<Parameter Name="diagramname" Mode="In" Type="String" />
<Parameter Name="owner_id" Mode="In" Type="Int32" />
</FunctionImport>
<FunctionImport Name="sp_helpdiagrams" ReturnType="Collection(MemoryMatchModel.sp_helpdiagrams_Result)">
<Parameter Name="diagramname" Mode="In" Type="String" />
<Parameter Name="owner_id" Mode="In" Type="Int32" />
</FunctionImport>
<FunctionImport Name="sp_renamediagram">
<Parameter Name="diagramname" Mode="In" Type="String" />
<Parameter Name="owner_id" Mode="In" Type="Int32" />
<Parameter Name="new_diagramname" Mode="In" Type="String" />
</FunctionImport>
<FunctionImport Name="sp_upgraddiagrams" />
</EntityContainer>
<ComplexType Name="sp_helpdiagramdefinition_Result">
<Property Type="Int32" Name="version" Nullable="true" />
<Property Type="Binary" Name="definition" Nullable="true" />
</ComplexType>
<ComplexType Name="sp_helpdiagrams_Result">
<Property Type="String" Name="Database" Nullable="true" MaxLength="128" />
<Property Type="String" Name="Name" Nullable="false" MaxLength="128" />
<Property Type="Int32" Name="ID" Nullable="false" />
<Property Type="String" Name="Owner" Nullable="true" MaxLength="128" />
<Property Type="Int32" Name="OwnerID" Nullable="false" />
</ComplexType>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
<EntityContainerMapping StorageEntityContainer="MemoryMatchModelStoreContainer" CdmEntityContainer="MemoryMatchEntities">
<EntitySetMapping Name="ContactMessages">
<EntityTypeMapping TypeName="MemoryMatchModel.ContactMessage">
<MappingFragment StoreEntitySet="ContactMessages">
<ScalarProperty Name="MessageID" ColumnName="MessageID" />
<ScalarProperty Name="MessageTimeStamp" ColumnName="MessageTimeStamp" />
<ScalarProperty Name="Phone" ColumnName="Phone" />
<ScalarProperty Name="Email" ColumnName="Email" />
<ScalarProperty Name="MessageText" ColumnName="MessageText" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<EntitySetMapping Name="Feedbacks">
<EntityTypeMapping TypeName="MemoryMatchModel.Feedback">
<MappingFragment StoreEntitySet="Feedbacks">
<ScalarProperty Name="FeedbackID" ColumnName="FeedbackID" />
<ScalarProperty Name="UserID" ColumnName="UserID" />
<ScalarProperty Name="FeedbackTimeStamp" ColumnName="FeedbackTimeStamp" />
<ScalarProperty Name="FeedbackText" ColumnName="FeedbackText" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<EntitySetMapping Name="GamesScores">
<EntityTypeMapping TypeName="MemoryMatchModel.GamesScore">
<MappingFragment StoreEntitySet="GamesScores">
<ScalarProperty Name="GameDuration" ColumnName="GameDuration" />
<ScalarProperty Name="GameScoreID" ColumnName="GameScoreID" />
<ScalarProperty Name="UserID" ColumnName="UserID" />
<ScalarProperty Name="GameSteps" ColumnName="GameSteps" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<EntitySetMapping Name="Images">
<EntityTypeMapping TypeName="MemoryMatchModel.Image">
<MappingFragment StoreEntitySet="Images">
<ScalarProperty Name="ImageID" ColumnName="ImageID" />
<ScalarProperty Name="ImageName" ColumnName="ImageName" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<EntitySetMapping Name="sysdiagrams">
<EntityTypeMapping TypeName="MemoryMatchModel.sysdiagram">
<MappingFragment StoreEntitySet="sysdiagrams">
<ScalarProperty Name="name" ColumnName="name" />
<ScalarProperty Name="principal_id" ColumnName="principal_id" />
<ScalarProperty Name="diagram_id" ColumnName="diagram_id" />
<ScalarProperty Name="version" ColumnName="version" />
<ScalarProperty Name="definition" ColumnName="definition" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<EntitySetMapping Name="Users">
<EntityTypeMapping TypeName="MemoryMatchModel.User">
<MappingFragment StoreEntitySet="Users">
<ScalarProperty Name="UserID" ColumnName="UserID" />
<ScalarProperty Name="FullName" ColumnName="FullName" />
<ScalarProperty Name="UserName" ColumnName="UserName" />
<ScalarProperty Name="Password" ColumnName="Password" />
<ScalarProperty Name="Email" ColumnName="Email" />
<ScalarProperty Name="Birthdate" ColumnName="Birthdate" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<FunctionImportMapping FunctionImportName="sp_alterdiagram" FunctionName="MemoryMatchModel.Store.sp_alterdiagram" />
<FunctionImportMapping FunctionImportName="sp_creatediagram" FunctionName="MemoryMatchModel.Store.sp_creatediagram" />
<FunctionImportMapping FunctionImportName="sp_dropdiagram" FunctionName="MemoryMatchModel.Store.sp_dropdiagram" />
<FunctionImportMapping FunctionImportName="sp_helpdiagramdefinition" FunctionName="MemoryMatchModel.Store.sp_helpdiagramdefinition">
<ResultMapping>
<ComplexTypeMapping TypeName="MemoryMatchModel.sp_helpdiagramdefinition_Result">
<ScalarProperty Name="version" ColumnName="version" />
<ScalarProperty Name="definition" ColumnName="definition" />
</ComplexTypeMapping>
</ResultMapping>
</FunctionImportMapping>
<FunctionImportMapping FunctionImportName="sp_helpdiagrams" FunctionName="MemoryMatchModel.Store.sp_helpdiagrams">
<ResultMapping>
<ComplexTypeMapping TypeName="MemoryMatchModel.sp_helpdiagrams_Result">
<ScalarProperty Name="Database" ColumnName="Database" />
<ScalarProperty Name="Name" ColumnName="Name" />
<ScalarProperty Name="ID" ColumnName="ID" />
<ScalarProperty Name="Owner" ColumnName="Owner" />
<ScalarProperty Name="OwnerID" ColumnName="OwnerID" />
</ComplexTypeMapping>
</ResultMapping>
</FunctionImportMapping>
<FunctionImportMapping FunctionImportName="sp_renamediagram" FunctionName="MemoryMatchModel.Store.sp_renamediagram" />
<FunctionImportMapping FunctionImportName="sp_upgraddiagrams" FunctionName="MemoryMatchModel.Store.sp_upgraddiagrams" />
</EntityContainerMapping>
</Mapping>
</edmx:Mappings>
</edmx:Runtime>
<!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
<Designer xmlns="http://schemas.microsoft.com/ado/2009/11/edmx">
<Connection>
<DesignerInfoPropertySet>
<DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
</DesignerInfoPropertySet>
</Connection>
<Options>
<DesignerInfoPropertySet>
<DesignerProperty Name="ValidateOnBuild" Value="true" />
<DesignerProperty Name="EnablePluralization" Value="true" />
<DesignerProperty Name="IncludeForeignKeysInModel" Value="true" />
<DesignerProperty Name="UseLegacyProvider" Value="false" />
<DesignerProperty Name="CodeGenerationStrategy" Value="None" />
</DesignerInfoPropertySet>
</Options>
<!-- Diagram content (shape and connector positions) -->
<Diagrams></Diagrams>
</Designer>
</edmx:Edmx>
Why can't I add the column GameDateCreation to my model from the database?
Is it because of the errors I mentioned?
You have mentioned column GameDateCreation under <EntityType Name="GamesScores"> in section SSDL. But, You have not mentioned same column GameDateCreation mentioned under <EntitySetMapping Name="GamesScores"> in Mappings section.
There should be below mentioned line code under <EntitySetMapping Name="GamesScores">.
<ScalarProperty Name="GameDateCreation" ColumnName="GameDateCreation" />
Other workaround will be remove all references of column GameDateCreation from edmx file and try to add column to model from database.
Please let me know how you go.

Convert XML value to a table using SQL

"I have a xml field with the following value:
<table>
<id>{cdf8cafc-2b3c-454b-aab8-c6c27e96b675}</id>
<rows>
<row>
<columns>
<column name="po_desc" value="Item-1" type="System.String" />
<column name="Qty" value="15" type="System.Int32" />
<column name="price" value="100" type="System.Decimal" />
<column name="linetotal" value="1500" type="System.Decimal" />
<column name="DefaultKey" value="1" type="System.Int32" />
</columns>
</row>
<row>
<columns>
<column name="po_desc" value="" type="System.String" />
<column name="Qty" value="1" type="System.Int32" />
<column name="price" value="1" type="System.Decimal" />
<column name="linetotal" value="1" type="System.Decimal" />
<column name="DefaultKey" value="2" type="System.Int32" />
</columns>
</row>
</rows>
</table>
And I need to transform this to Row and columns as below
PO_desc Qty Price LineTotal
=====================================
item-1 15 100 1500
Item-2 1 1 1
=======================================
using MS SQL Query.
Try it like this
DECLARE #DummyTable TABLE(ID INT IDENTITY, YourXmlColumn XML);
INSERT INTO #DummyTable VALUES
('<table>
<id>{cdf8cafc-2b3c-454b-aab8-c6c27e96b675}</id>
<rows>
<row>
<columns>
<column name="po_desc" value="Item-1" type="System.String" />
<column name="Qty" value="15" type="System.Int32" />
<column name="price" value="100" type="System.Decimal" />
<column name="linetotal" value="1500" type="System.Decimal" />
<column name="DefaultKey" value="1" type="System.Int32" />
</columns>
</row>
<row>
<columns>
<column name="po_desc" value="" type="System.String" />
<column name="Qty" value="1" type="System.Int32" />
<column name="price" value="1" type="System.Decimal" />
<column name="linetotal" value="1" type="System.Decimal" />
<column name="DefaultKey" value="2" type="System.Int32" />
</columns>
</row>
</rows>
</table>');
This is the query
SELECT r.value('(columns/column[#name="po_desc"]/#value)[1]','nvarchar(max)') AS PO_Desc
,r.value('(columns/column[#name="Qty"]/#value)[1]','int') AS Qty
,r.value('(columns/column[#name="price"]/#value)[1]','decimal') AS Price
,r.value('(columns/column[#name="linetotal"]/#value)[1]','decimal') AS LineTotal
FROM #DummyTable AS t
CROSS APPLY t.YourXmlColumn.nodes('/table/rows/row') AS A(r);

Shredding XML file is not returning all of the data

I have an XML file that looks like this:
<extensionG>
<Tables>
<Table TName="__MigrationHistory" Schema="dbo" TextImageOnFileGroup="PRIMARY">
<Columns>
<Column CName="MigrationId" DataType="nvarchar" DataTypeMaxLength="300" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="1" />
<Column CName="ContextKey" DataType="nvarchar" DataTypeMaxLength="600" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="1" />
<Column CName="Model" DataType="varbinary" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="ProductVersion" DataType="nvarchar" DataTypeMaxLength="64" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="0" />
</Columns>
</Table>
<Table TName="CoatingCost" Schema="dbo">
<Columns>
<Column CName="CoatingCostId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="1" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="1" />
<Column CName="CoatingId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="LabId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="1" PrimaryKey="0" />
<Column CName="Cost" DataType="money" DataTypeMaxLength="8" DataTypePrecision="19" DataTypeScale="4" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="Price" DataType="money" DataTypeMaxLength="8" DataTypePrecision="19" DataTypeScale="4" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
</Columns>
</Table>
<Table TName="ContactLens" Schema="dbo">
<Columns>
<Column CName="ProductId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="0" />
</Columns>
</Table>
</Tables>
</extensionG>
I shred the xml file using this query and put it into a temporary table:
INSERT INTO #TargetDBObjects
SELECT DBTables.Name.value('#TName', 'varchar(100)') AS TableName, DBTables.Name.value('#Schema', 'varchar(20)') AS SchemaName, DBTables.Name.value('#TextImageOnFileGroup', 'varchar(20)') AS TextImageFileGroup,
Cols.C.value('#CName', 'varchar(100)') AS ColName, Cols.C.value('#DataType', 'varchar(20)') AS DataType, Cols.C.value('#DataTypeMaxLength', 'varchar(5)') AS DataTypeMaxLength,
Cols.C.value('#DataTypePrecision', 'varchar(5)') AS DataTypePrecision, Cols.C.value('#DataTypeScale', 'varchar(5)') AS DataTypeScale,
Cols.C.value('#IsIdentityColumn', 'varchar(1)') AS IsIdentityColumn, Cols.C.value('#IdentitySeedValue', 'varchar(5)') AS IdentitySeedValue, Cols.C.value('#IdentityIncrementValue', 'varchar(5)') AS IdentityIncrementValue,
Cols.C.value('#IsColumnNullable', 'varchar(1)') AS IsColumnNullable, Cols.C.value('#PrimaryKey', 'varchar(1)') AS PrimaryKey
FROM #XmlTargetDB.nodes('//Tables/Table') AS DBTables(Name)
CROSS APPLY DBTables.Name.nodes('Columns/Column') AS Cols(C)
When I do a SELECT on the table, the __MigrationHistory and CoatingCost table data is present but not the ContactLens data
Can anybody see anything wrong with the XML file or the query that shreds the xml?
UPDATE
This is a more complete example of the xml file and the entire query that shreds the document:
'<extensionG>
<Tables>
<Table TName="__MigrationHistory" Schema="dbo" TextImageOnFileGroup="PRIMARY">
<Columns>
<Column CName="MigrationId" DataType="nvarchar" DataTypeMaxLength="300" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="1" />
<Column CName="ContextKey" DataType="nvarchar" DataTypeMaxLength="600" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="1" />
<Column CName="Model" DataType="varbinary" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="ProductVersion" DataType="nvarchar" DataTypeMaxLength="64" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="0" />
</Columns>
<Indexes>
<Index IndexName="PK_dbo.__MigrationHistory" PrimaryKeyIndex="1" IndexDescription="CLUSTERED" PadIndex="0" Statistics_NoRecompute="0" IgnoreDupKey="0" AllowRowLocks="1" AllowPageLocks="1">
<IndexColumn ICName="MigrationId" IsDescendingSort="0" OrdinalPosition="1" />
<IndexColumn ICName="ContextKey" IsDescendingSort="0" OrdinalPosition="2" />
</Index>
</Indexes>
</Table>
<Table TName="Activity" Schema="dbo" TextImageOnFileGroup="PRIMARY">
<Columns>
<Column CName="ActivityId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="1" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="1" />
<Column CName="ApplicationId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="Name" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="Description" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="Code" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
</Columns>
<ForeignKeys>
<ForeignKey FK_Name="FK_dbo.Activity_dbo.Application_ApplicationId" ParentColumn="ApplicationId" ReferenceTable="Application" ReferenceColumn="ApplicationId" IsDisabled="0" HasUpdateRefAction="0" HasDeleteRefAction="1" />
</ForeignKeys>
<Indexes>
<Index IndexName="PK_dbo.Activity" PrimaryKeyIndex="1" IndexDescription="CLUSTERED" PadIndex="0" Statistics_NoRecompute="0" IgnoreDupKey="0" AllowRowLocks="1" AllowPageLocks="1">
<IndexColumn ICName="ActivityId" IsDescendingSort="0" OrdinalPosition="1" />
</Index>
<Index IndexName="IX_ApplicationId" PrimaryKeyIndex="0" IndexDescription="NONCLUSTERED" PadIndex="0" Statistics_NoRecompute="0" IgnoreDupKey="0" AllowRowLocks="1" AllowPageLocks="1">
<IndexColumn ICName="ApplicationId" IsDescendingSort="0" OrdinalPosition="1" />
</Index>
</Indexes>
</Table>
<Table TName="AdHocContacts" Schema="dbo" TextImageOnFileGroup="PRIMARY">
<Columns>
<Column CName="AdHocContactId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="1" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="PatientProfileId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="Name" DataType="varchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="Fax" DataType="varchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="1" PrimaryKey="0" />
<Column CName="Email" DataType="varchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="1" PrimaryKey="0" />
</Columns>
</Table>
<Table TName="AdjustmentType" Schema="dbo">
<Columns>
<Column CName="AdjustmentId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="1" />
<Column CName="AdjustmentName" DataType="nvarchar" DataTypeMaxLength="100" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="0" />
</Columns>
<Indexes>
<Index IndexName="PK_AdjustmentType" PrimaryKeyIndex="1" IndexDescription="CLUSTERED" PadIndex="0" Statistics_NoRecompute="0" IgnoreDupKey="0" AllowRowLocks="1" AllowPageLocks="1">
<IndexColumn ICName="AdjustmentId" IsDescendingSort="0" OrdinalPosition="1" />
</Index>
</Indexes>
</Table>
<Table TName="Application" Schema="dbo" TextImageOnFileGroup="PRIMARY">
<Columns>
<Column CName="ApplicationId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="1" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="1" />
<Column CName="Code" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="Name" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
</Columns>
<Indexes>
<Index IndexName="PK_dbo.Application" PrimaryKeyIndex="1" IndexDescription="CLUSTERED" PadIndex="0" Statistics_NoRecompute="0" IgnoreDupKey="0" AllowRowLocks="1" AllowPageLocks="1">
<IndexColumn ICName="ApplicationId" IsDescendingSort="0" OrdinalPosition="1" />
</Index>
</Indexes>
</Table>
<Table TName="ApplicationCategory" Schema="dbo">
<Columns>
<Column CName="ApplicationId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="1" />
<Column CName="CategoryId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="1" />
</Columns>
<ForeignKeys>
<ForeignKey FK_Name="FK_ApplicationCategory_Application" ParentColumn="ApplicationId" ReferenceTable="Application" ReferenceColumn="ApplicationId" IsDisabled="0" HasUpdateRefAction="0" HasDeleteRefAction="0" />
<ForeignKey FK_Name="FK_ApplicationCategory_Category" ParentColumn="CategoryId" ReferenceTable="Category" ReferenceColumn="CategoryId" IsDisabled="0" HasUpdateRefAction="0" HasDeleteRefAction="0" />
</ForeignKeys>
<Indexes>
<Index IndexName="PK_ApplicationCategory" PrimaryKeyIndex="1" IndexDescription="CLUSTERED" PadIndex="0" Statistics_NoRecompute="0" IgnoreDupKey="0" AllowRowLocks="1" AllowPageLocks="1">
<IndexColumn ICName="ApplicationId" IsDescendingSort="0" OrdinalPosition="1" />
<IndexColumn ICName="CategoryId" IsDescendingSort="0" OrdinalPosition="2" />
</Index>
</Indexes>
</Table>
<Table TName="ApplicationSetting" Schema="dbo" TextImageOnFileGroup="PRIMARY">
<Columns>
<Column CName="SettingId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="1" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="ApplicationId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="SettingKey" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="1" PrimaryKey="0" />
<Column CName="Value" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="1" PrimaryKey="0" />
</Columns>
</Table>
<Table TName="Bookmark" Schema="dbo" TextImageOnFileGroup="PRIMARY">
<Columns>
<Column CName="BookmarkId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="1" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="UserName" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="Url" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="1" PrimaryKey="0" />
<Column CName="Name" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="1" PrimaryKey="0" />
</Columns>
</Table>
<Table TName="Bundle" Schema="dbo" TextImageOnFileGroup="PRIMARY">
<Columns>
<Column CName="BundleId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="1" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="1" />
<Column CName="Name" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
</Columns>
<Indexes>
<Index IndexName="PK_dbo.Bundle" PrimaryKeyIndex="1" IndexDescription="CLUSTERED" PadIndex="0" Statistics_NoRecompute="0" IgnoreDupKey="0" AllowRowLocks="1" AllowPageLocks="1">
<IndexColumn ICName="BundleId" IsDescendingSort="0" OrdinalPosition="1" />
</Index>
</Indexes>
</Table>
<Table TName="BundleProduct" Schema="dbo">
<Columns>
<Column CName="BundleId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="1" />
<Column CName="ProductId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="1" />
</Columns>
<ForeignKeys>
<ForeignKey FK_Name="FK_dbo.BundleProduct_dbo.Bundle_BundleId" ParentColumn="BundleId" ReferenceTable="Bundle" ReferenceColumn="BundleId" IsDisabled="0" HasUpdateRefAction="0" HasDeleteRefAction="1" />
<ForeignKey FK_Name="FK_dbo.BundleProduct_dbo.Product_ProductId" ParentColumn="ProductId" ReferenceTable="Product" ReferenceColumn="ProductId" IsDisabled="0" HasUpdateRefAction="0" HasDeleteRefAction="1" />
</ForeignKeys>
<Indexes>
<Index IndexName="PK_dbo.BundleProduct" PrimaryKeyIndex="1" IndexDescription="CLUSTERED" PadIndex="0" Statistics_NoRecompute="0" IgnoreDupKey="0" AllowRowLocks="1" AllowPageLocks="1">
<IndexColumn ICName="BundleId" IsDescendingSort="0" OrdinalPosition="1" />
<IndexColumn ICName="ProductId" IsDescendingSort="0" OrdinalPosition="2" />
</Index>
<Index IndexName="IX_BundleId" PrimaryKeyIndex="0" IndexDescription="NONCLUSTERED" PadIndex="0" Statistics_NoRecompute="0" IgnoreDupKey="0" AllowRowLocks="1" AllowPageLocks="1">
<IndexColumn ICName="BundleId" IsDescendingSort="0" OrdinalPosition="1" />
</Index>
<Index IndexName="IX_ProductId" PrimaryKeyIndex="0" IndexDescription="NONCLUSTERED" PadIndex="0" Statistics_NoRecompute="0" IgnoreDupKey="0" AllowRowLocks="1" AllowPageLocks="1">
<IndexColumn ICName="ProductId" IsDescendingSort="0" OrdinalPosition="1" />
</Index>
</Indexes>
<Triggers>
<Trigger TriggerName="TestTrigger2" TrigDefinition="-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE TRIGGER TestTrigger2
ON BundleProduct
AFTER DELETE,UPDATE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for trigger here
select * from Edging;
END
" IsUpdateTrig="1" IsDeleteTrig="1" IsInsertTrig="0" IsAfterTrig="1" IsInsteadOfTrig="0" IsDisabled="0" />
</Triggers>
</Table>
<Table TName="Category" Schema="dbo">
<Columns>
<Column CName="CategoryId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="1" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="1" />
<Column CName="Name" DataType="varchar" DataTypeMaxLength="50" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="1" PrimaryKey="0" />
</Columns>
<Indexes>
<Index IndexName="PK_Category" PrimaryKeyIndex="1" IndexDescription="CLUSTERED" PadIndex="0" Statistics_NoRecompute="0" IgnoreDupKey="0" AllowRowLocks="1" AllowPageLocks="1">
<IndexColumn ICName="CategoryId" IsDescendingSort="0" OrdinalPosition="1" />
</Index>
</Indexes>
</Table>
<Table TName="Coating" Schema="dbo" TextImageOnFileGroup="PRIMARY">
<Columns>
<Column CName="CoatingId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="1" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="1" />
<Column CName="Name" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="Inactive" DataType="bit" DataTypeMaxLength="1" DataTypePrecision="1" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="ProcedureCode" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="1" PrimaryKey="0" />
</Columns>
<Indexes>
<Index IndexName="PK_Coatings" PrimaryKeyIndex="1" IndexDescription="CLUSTERED" PadIndex="0" Statistics_NoRecompute="0" IgnoreDupKey="0" AllowRowLocks="1" AllowPageLocks="1">
<IndexColumn ICName="CoatingId" IsDescendingSort="0" OrdinalPosition="1" />
</Index>
</Indexes>
</Table>
<Table TName="CoatingCost" Schema="dbo">
<Columns>
<Column CName="CoatingCostId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="1" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="1" />
<Column CName="CoatingId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="LabId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="1" PrimaryKey="0" />
<Column CName="Cost" DataType="money" DataTypeMaxLength="8" DataTypePrecision="19" DataTypeScale="4" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
<Column CName="Price" DataType="money" DataTypeMaxLength="8" DataTypePrecision="19" DataTypeScale="4" IsIdentityColumn="0" IdentitySeedValue="1" IdentityIncrementValue="1" IsColumnNullable="0" PrimaryKey="0" />
</Columns>
<ForeignKeys>
<ForeignKey FK_Name="FK_CoatingCost_Coating" ParentColumn="CoatingId" ReferenceTable="Coating" ReferenceColumn="CoatingId" IsDisabled="0" HasUpdateRefAction="0" HasDeleteRefAction="0" />
<ForeignKey FK_Name="FK_CoatingCost_Lab" ParentColumn="LabId" ReferenceTable="Lab" ReferenceColumn="LabId" IsDisabled="0" HasUpdateRefAction="0" HasDeleteRefAction="0" />
</ForeignKeys>
<Indexes>
<Index IndexName="PK_CoatingCost" PrimaryKeyIndex="1" IndexDescription="CLUSTERED" PadIndex="0" Statistics_NoRecompute="0" IgnoreDupKey="0" AllowRowLocks="1" AllowPageLocks="1">
<IndexColumn ICName="CoatingCostId" IsDescendingSort="0" OrdinalPosition="1" />
</Index>
</Indexes>
</Table>
<Table TName="ContactLens" Schema="dbo">
<Columns>
<Column CName="ProductId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="0" />
</Columns>
</Table>
<Table TName="Contacts" Schema="dbo" TextImageOnFileGroup="PRIMARY">
<Columns>
<Column CName="BaseCurve" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="1" PrimaryKey="0" />
<Column CName="Cylinder" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="1" PrimaryKey="0" />
<Column CName="Diameter" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="1" PrimaryKey="0" />
<Column CName="Power" DataType="nvarchar" DataTypeMaxLength="-1" DataTypePrecision="0" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="1" PrimaryKey="0" />
<Column CName="ProductId" DataType="int" DataTypeMaxLength="4" DataTypePrecision="10" DataTypeScale="0" IsIdentityColumn="0" IsColumnNullable="0" PrimaryKey="1" />
</Columns>
<ForeignKeys>
<ForeignKey FK_Name="FK_Contacts_Product" ParentColumn="ProductId" ReferenceTable="Product" ReferenceColumn="ProductId" IsDisabled="0" HasUpdateRefAction="0" HasDeleteRefAction="0" />
</ForeignKeys>
<Indexes>
<Index IndexName="PK_Contacts" PrimaryKeyIndex="1" IndexDescription="CLUSTERED" PadIndex="0" Statistics_NoRecompute="0" IgnoreDupKey="0" AllowRowLocks="1" AllowPageLocks="1">
<IndexColumn ICName="ProductId" IsDescendingSort="0" OrdinalPosition="1" />
</Index>
</Indexes>
</Table>
</Tables>
</extensionG>';
This is the query:
SELECT DBTables.Name.value('#TName', 'varchar(100)') AS TableName, DBTables.Name.value('#Schema', 'varchar(20)') AS SchemaName, DBTables.Name.value('#TextImageOnFileGroup', 'varchar(20)') AS TextImageFileGroup,
Cols.C.value('#CName', 'varchar(100)') AS ColName, Cols.C.value('#DataType', 'varchar(20)') AS DataType, Cols.C.value('#DataTypeMaxLength', 'varchar(5)') AS DataTypeMaxLength,
Cols.C.value('#DataTypePrecision', 'varchar(5)') AS DataTypePrecision, Cols.C.value('#DataTypeScale', 'varchar(5)') AS DataTypeScale,
Cols.C.value('#IsIdentityColumn', 'varchar(1)') AS IsIdentityColumn, Cols.C.value('#IdentitySeedValue', 'varchar(5)') AS IdentitySeedValue, Cols.C.value('#IdentityIncrementValue', 'varchar(5)') AS IdentityIncrementValue,
Cols.C.value('#IsColumnNullable', 'varchar(1)') AS IsColumnNullable, Cols.C.value('#PrimaryKey', 'varchar(1)') AS PrimaryKey,
[Indexes].I.value('#IndexName', 'varchar(100)') AS IndexName, [Indexes].I.value('#PrimaryKeyIndex', 'varchar(1)') AS PrimaryKeyIndex, [Indexes].I.value('#IsUnique', 'varchar(1)') AS IsUnique,
[Indexes].I.value('#IndexDescription', 'varchar(120)') AS IndexDescription,
[Indexes].I.value('#PadIndex', 'varchar(1)') AS PadIndex, [Indexes].I.value('#Statistics_NoRecompute', 'varchar(1)') AS StatisticsNoRecompute, [Indexes].I.value('#IgnoreDupKey', 'varchar(1)') AS IgnoreDupKey,
[Indexes].I.value('#AllowRowLocks', 'varchar(1)') AS AllowRowLocks, [Indexes].I.value('#AllowPageLocks', 'varchar(1)') AS AllowPageLocks,
[IndexColumn].IC.value('#ICName', 'varchar(100)') AS IndexColumnName, [IndexColumn].IC.value('#IsDescendingSort', 'varchar(1)') AS IsDescendingSort,
[IndexColumn].IC.value('#OrdinalPosition', 'varchar(2)') AS OrdinalPosition,
ForeignKey.FK.value('#FK_Name', 'varchar(100)') AS ForeignKeyName,
ForeignKey.FK.value('#ParentColumn', 'varchar(50)') AS ParentColumn,
ForeignKey.FK.value('#ReferenceTable', 'varchar(100)') AS ReferenceTable, ForeignKey.FK.value('#ReferenceColumn', 'varchar(50)') AS ReferenceColumn,
ForeignKey.FK.value('#IsDisabled', 'varchar(1)') AS IsDisabled, ForeignKey.FK.value('#HasUpdateRefAction', 'varchar(1)') AS HasUpdateRefAction, ForeignKey.FK.value('#HasDeleteRefAction', 'varchar(1)') AS HasDeleteRefAction,
Defaults.D.value('#DefName', 'varchar(100)') AS DefaultName, Defaults.D.value('#DefValue', 'varchar(100)') AS DefaultValue, Defaults.D.value('#DefColumnName', 'varchar(100)') AS DefColumnName,
Checks.C.value('#CkName', 'varchar(100)') AS CheckName, Checks.C.value('#CkDefinition', 'varchar(500)') AS CkDefinition, Checks.C.value('#IsCkDisabled', 'varchar(1)') AS IsCkDisabled,
[Triggers].T.value('#TriggerName', 'varchar(100)') AS TriggerName, [Triggers].T.value('#TrigDefinition', 'varchar(max)') AS TrigDefinition,
[Triggers].T.value('#IsUpdateTrig', 'varchar(1)') AS IsUpdateTrigger, [Triggers].T.value('#IsDeleteTrig', 'varchar(1)') AS IsDeleteTrigger, [Triggers].T.value('#IsInsertTrig', 'varchar(1)') AS IsInsertTrigger,
[Triggers].T.value('#IsAfterTrig', 'varchar(1)') AS IsAfterTrigger, [Triggers].T.value('#IsInsteadOfTrig', 'varchar(1)') AS IsInsteadOfTrigger, [Triggers].T.value('#IsDisabled', 'varchar(1)') AS IsDisabledTrigger
FROM #XmlTargetDB.nodes('//Tables/Table') AS DBTables(Name)
CROSS APPLY DBTables.Name.nodes('Columns/Column') AS Cols(C)
OUTER APPLY DBTables.Name.nodes('Indexes/Index') AS [Indexes](I)
CROSS APPLY I.nodes('IndexColumn') AS [IndexColumn](IC)
OUTER APPLY DBTables.Name.nodes('ForeignKeys/ForeignKey') AS ForeignKey(FK)
OUTER APPLY DBTables.Name.nodes('DefaultConstraints/Default') AS Defaults(D)
OUTER APPLY DBTables.Name.nodes('CheckConstraints/Check') AS Checks(C)
OUTER APPLY DBTables.Name.nodes('Triggers/Trigger') AS [Triggers](T)
When I change the one CROSS APPLY you have there to an OUTER APPLY the missing table is there.
Your table "ContactLens" does not have a sub-tree <indexes> ...
SELECT DBTables.Name.value('#TName', 'varchar(100)') AS TableName, DBTables.Name.value('#Schema', 'varchar(20)') AS SchemaName, DBTables.Name.value('#TextImageOnFileGroup', 'varchar(20)') AS TextImageFileGroup,
Cols.C.value('#CName', 'varchar(100)') AS ColName, Cols.C.value('#DataType', 'varchar(20)') AS DataType, Cols.C.value('#DataTypeMaxLength', 'varchar(5)') AS DataTypeMaxLength,
Cols.C.value('#DataTypePrecision', 'varchar(5)') AS DataTypePrecision, Cols.C.value('#DataTypeScale', 'varchar(5)') AS DataTypeScale,
Cols.C.value('#IsIdentityColumn', 'varchar(1)') AS IsIdentityColumn, Cols.C.value('#IdentitySeedValue', 'varchar(5)') AS IdentitySeedValue, Cols.C.value('#IdentityIncrementValue', 'varchar(5)') AS IdentityIncrementValue,
Cols.C.value('#IsColumnNullable', 'varchar(1)') AS IsColumnNullable, Cols.C.value('#PrimaryKey', 'varchar(1)') AS PrimaryKey,
[Indexes].I.value('#IndexName', 'varchar(100)') AS IndexName, [Indexes].I.value('#PrimaryKeyIndex', 'varchar(1)') AS PrimaryKeyIndex, [Indexes].I.value('#IsUnique', 'varchar(1)') AS IsUnique,
[Indexes].I.value('#IndexDescription', 'varchar(120)') AS IndexDescription,
[Indexes].I.value('#PadIndex', 'varchar(1)') AS PadIndex, [Indexes].I.value('#Statistics_NoRecompute', 'varchar(1)') AS StatisticsNoRecompute, [Indexes].I.value('#IgnoreDupKey', 'varchar(1)') AS IgnoreDupKey,
[Indexes].I.value('#AllowRowLocks', 'varchar(1)') AS AllowRowLocks, [Indexes].I.value('#AllowPageLocks', 'varchar(1)') AS AllowPageLocks,
[IndexColumn].IC.value('#ICName', 'varchar(100)') AS IndexColumnName, [IndexColumn].IC.value('#IsDescendingSort', 'varchar(1)') AS IsDescendingSort,
[IndexColumn].IC.value('#OrdinalPosition', 'varchar(2)') AS OrdinalPosition,
ForeignKey.FK.value('#FK_Name', 'varchar(100)') AS ForeignKeyName,
ForeignKey.FK.value('#ParentColumn', 'varchar(50)') AS ParentColumn,
ForeignKey.FK.value('#ReferenceTable', 'varchar(100)') AS ReferenceTable, ForeignKey.FK.value('#ReferenceColumn', 'varchar(50)') AS ReferenceColumn,
ForeignKey.FK.value('#IsDisabled', 'varchar(1)') AS IsDisabled, ForeignKey.FK.value('#HasUpdateRefAction', 'varchar(1)') AS HasUpdateRefAction, ForeignKey.FK.value('#HasDeleteRefAction', 'varchar(1)') AS HasDeleteRefAction,
Defaults.D.value('#DefName', 'varchar(100)') AS DefaultName, Defaults.D.value('#DefValue', 'varchar(100)') AS DefaultValue, Defaults.D.value('#DefColumnName', 'varchar(100)') AS DefColumnName,
Checks.C.value('#CkName', 'varchar(100)') AS CheckName, Checks.C.value('#CkDefinition', 'varchar(500)') AS CkDefinition, Checks.C.value('#IsCkDisabled', 'varchar(1)') AS IsCkDisabled,
[Triggers].T.value('#TriggerName', 'varchar(100)') AS TriggerName, [Triggers].T.value('#TrigDefinition', 'varchar(max)') AS TrigDefinition,
[Triggers].T.value('#IsUpdateTrig', 'varchar(1)') AS IsUpdateTrigger, [Triggers].T.value('#IsDeleteTrig', 'varchar(1)') AS IsDeleteTrigger, [Triggers].T.value('#IsInsertTrig', 'varchar(1)') AS IsInsertTrigger,
[Triggers].T.value('#IsAfterTrig', 'varchar(1)') AS IsAfterTrigger, [Triggers].T.value('#IsInsteadOfTrig', 'varchar(1)') AS IsInsteadOfTrigger, [Triggers].T.value('#IsDisabled', 'varchar(1)') AS IsDisabledTrigger
FROM #XmlTargetDB.nodes('//Tables/Table') AS DBTables(Name)
CROSS APPLY DBTables.Name.nodes('Columns/Column') AS Cols(C)
OUTER APPLY DBTables.Name.nodes('Indexes/Index') AS [Indexes](I)
OUTER APPLY I.nodes('IndexColumn') AS [IndexColumn](IC)
OUTER APPLY DBTables.Name.nodes('ForeignKeys/ForeignKey') AS ForeignKey(FK)
OUTER APPLY DBTables.Name.nodes('DefaultConstraints/Default') AS Defaults(D)
OUTER APPLY DBTables.Name.nodes('CheckConstraints/Check') AS Checks(C)
OUTER APPLY DBTables.Name.nodes('Triggers/Trigger') AS [Triggers](T)

Bulk inserting data with XML format file in MS SQL?

I am pretty new to databases (normally stored everything locally on CSV or HDFS files). I have access to MS SQL Server and I have been trying to load some historical data into the database. I was successful finally and I want to redo my steps for other data, but first I want to make sure that I am being efficient.
1) I create a table using a query and specify the data type of each column and the number of characters (I used len() in Excel and then added a buffer just in case)
2) I then created an XML file, example is below. I notated the delimiter and the data type for each column along with things like max_length and precision/scale where needed.
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="1" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="2" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="3" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="4" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="5" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="6" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="7" xsi:type="CharTerm" TERMINATOR="," MAX_LENGTH="10"/>
<FIELD ID="8" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="9" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="10" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="11" xsi:type="CharTerm" TERMINATOR="," MAX_LENGTH="3"/>
<FIELD ID="12" xsi:type="CharTerm" TERMINATOR="," MAX_LENGTH="3"/>
<FIELD ID="13" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="14" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="15" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="16" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="17" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="18" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="19" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="20" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="21" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="22" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="23" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="24" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="25" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="26" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="27" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="28" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="29" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="30" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="31" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="32" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="33" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="34" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="35" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="36" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="37" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="38" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="39" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="40" xsi:type="CharTerm" TERMINATOR=","/>
<FIELD ID="41" xsi:type="CharTerm" TERMINATOR="\r\n"/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="date" xsi:type="SQLDATE"/>
<COLUMN SOURCE="2" NAME="time" xsi:type="SQLDATETIME"/>
<COLUMN SOURCE="3" NAME="other_date" xsi:type="SQLDATE"/>
<COLUMN SOURCE="4" NAME="other_time" xsi:type="SQLDATETIME"/>
<COLUMN SOURCE="5" NAME="client_id" xsi:type="SQLINT"/>
<COLUMN SOURCE="6" NAME="location_id" xsi:type="SQLSMALLINT"/>
<COLUMN SOURCE="7" NAME="other_id" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="8" NAME="stuff_1" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="9" NAME="stuff_2" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="10" NAME="email" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="11" NAME="something_active" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="12" NAME="something_active" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="13" NAME="etc" xsi:type="SQLSMALLINT"/>
<COLUMN SOURCE="14" NAME="etc2" xsi:type="SQLDECIMAL" PRECISION="18" SCALE="2"/>
<COLUMN SOURCE="15" NAME="filler" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="16" NAME="filler" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="17" NAME="fk1" xsi:type="SQLSMALLINT"/>
<COLUMN SOURCE="18" NAME="fk2" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="19" NAME="fk3" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="20" NAME="fk4" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="21" NAME="fk5" xsi:type="SQLSMALLINT"/>
<COLUMN SOURCE="22" NAME="fk6" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="23" NAME="fk7" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="24" NAME="data1" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="25" NAME="data" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="26" NAME="data" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="27" NAME="data" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="28" NAME="data" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="29" NAME="data" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="30" NAME="data" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="31" NAME="data" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="32" NAME="data" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="33" NAME="data" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="34" NAME="data" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="35" NAME="data" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="36" NAME="data" xsi:type="SQLDECIMAL" PRECISION="5" SCALE="2"/>
<COLUMN SOURCE="37" NAME="data" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="38" NAME="data" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="39" NAME="data" xsi:type="SQLTINYINT"/>
<COLUMN SOURCE="40" NAME="data" xsi:type="SQLDECIMAL" PRECISION="5" SCALE="0"/>
<COLUMN SOURCE="41" NAME="data" xsi:type="SQLTINYINT"/>
</ROW>
</BCPFORMAT>
This worked and it was pretty fast for a few million rows. My question now is whether I need to do this for each file I am going to import (each is probably around 1 million to about 20 million records)? It is somewhat tedious creating a separate CREATE TABLE query and XML file per file, but it should only be a one time thing. Just want to make sure that I am not missing out on a more efficient approach to this whole thing.

Resources