dbTalk Databases Forums  

How can XML Bulk Load assign automatically a PK to a column?

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss How can XML Bulk Load assign automatically a PK to a column? in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
David Grant
 
Posts: n/a

Default How can XML Bulk Load assign automatically a PK to a column? - 03-07-2005 , 09:40 AM






Hi to everybody!

I'm trying to make the Bulk Load of an XML file with some tables and I
want to make SQL Server 2000 to assign a PK to a column determined in
the XSD file (I expecto to find an option that allows me to see the
key icon on a column when I click the Design Table option.)I've been
searching in the MSDN library and I haven't found anything. If anybody
had any suggerence it'd be very wellcomed.


These are the XML and XSD file:

<?xml version="1.0" encoding="utf-8" ?>
<IND_UNICO schemaVersion="1">
<DATOS NUM_DOC="3789">
<NOTARIO_ID>7</NOTARIO_ID>
<DOC NUM_OBJ="14" NUM_OPE="781" NUM_SUJ="587">
<DOCUMENTO_ID>555</DOCUMENTO_ID>
<OPE>
<OPERACION_ID>4052</OPERACION_ID>
<INMUEBLE>
<INMUEBLE_ID>44</INMUEBLE_ID>
<INMUEBLE_TIPO>casa</INMUEBLE_TIPO>
<INMUEBLE_VALOR>37000000</INMUEBLE_VALOR>
</INMUEBLE>
</OPE>
</DOC>
</DATOS>
<DATOS NUM_DOC="3791">
<NOTARIO_ID>9</NOTARIO_ID>
<DOC NUM_OBJ="17" NUM_OPE="784" NUM_SUJ="589">
<DOCUMENTO_ID>666</DOCUMENTO_ID>
<OPE>
<OPERACION_ID>3036</OPERACION_ID>
<INMUEBLE>
<INMUEBLE_ID>99</INMUEBLE_ID>
<INMUEBLE_TIPO>piso</INMUEBLE_TIPO>
<INMUEBLE_VALOR>46000000</INMUEBLE_VALOR>
</INMUEBLE>
</OPE>
</DOC>
</DATOS>
</IND_UNICO>


And this is the XSD file:

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema"
version="2.1.3">

<xsd:annotation>
<xsd:appinfo>
<sql:relationship
name="INDICE_DATOS"
parent="tblINDICE"
parent-key="idIndice"
child="tblDATOS"
child-key="idIndice"
/>
<sql:relationship
name="DATOS_DOCUMENTOS"
parent="tblDATOS"
parent-key="idDatos"
child="tblDOCUMENTOS"
child-key="idDatos"
/>
<sql:relationship
name="DOCUMENTOS_OPERACIONES"
parent="tblDOCUMENTOS"
parent-key="idDocumento"
child="tblOPERACIONES"
child-key="idDocumento"
/>
<sql:relationship
name="OPERACIONES_INMUEBLES"
parent="tblOPERACIONES"
parent-key="idOperacion"
child="tblINMUEBLES"
child-key="idOperacion"
/>
</xsd:appinfo>
</xsd:annotation>


<xsd:element name="IND_UNICO" sql:relation="tblINDICE">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="DATOS" maxOccurs="unbounded"
sql:relation="tblDATOS"
sql:relationship="INDICE_DATOS">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="DOC"
sql:relation="tblDOCUMENTOS"
sql:relationship="DATOS_DOCUMENTOS">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="OPE"
sql:relation="tblOPERACIONES"

sql:relationship="DOCUMENTOS_OPERACIONES">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="INMUEBLE"
sql:relation="tblINMUEBLES"

sql:relationship="OPERACIONES_INMUEBLES">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="INMUEBLE_ID"

type="xsd:short"/>
<xsd:element name="INMUEBLE_TIPO"

type="xsd:string"/>
<xsd:element name="INMUEBLE_VALOR"

type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="OPERACION_ID"

type="xsd:short"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="DOCUMENTO_ID"

type="xsd:short"/>
</xsd:sequence>
<xsd:attribute name="NUM_OBJ" type="xsd:short"
use="required"/>
<xsd:attribute name="NUM_OPE" type="xsd:short"
use="required"/>
<xsd:attribute name="NUM_SUJ" type="xsd:short"
use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="NOTARIO_ID" type="xsd:short"/>
</xsd:sequence>
<xsd:attribute name="NUM_DOC" type="xsd:short" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="schemaVersion" type="xsd:short"
use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>



Greetings,
David Grant

Reply With Quote
  #2  
Old   
Darren Green
 
Posts: n/a

Default Re: How can XML Bulk Load assign automatically a PK to a column? - 03-07-2005 , 12:13 PM






The table is not created by the bulk load tool is it? From memory it isn't
so I would expect you to have created the PK in advance. I don't think a
load should change the structure, just the data.


"David Grant" <icebold54 (AT) hotmail (DOT) com> wrote

Quote:
Hi to everybody!

I'm trying to make the Bulk Load of an XML file with some tables and I
want to make SQL Server 2000 to assign a PK to a column determined in
the XSD file (I expecto to find an option that allows me to see the
key icon on a column when I click the Design Table option.)I've been
searching in the MSDN library and I haven't found anything. If anybody
had any suggerence it'd be very wellcomed.


These are the XML and XSD file:

?xml version="1.0" encoding="utf-8" ?
IND_UNICO schemaVersion="1"
DATOS NUM_DOC="3789"
NOTARIO_ID>7</NOTARIO_ID
DOC NUM_OBJ="14" NUM_OPE="781" NUM_SUJ="587"
DOCUMENTO_ID>555</DOCUMENTO_ID
OPE
OPERACION_ID>4052</OPERACION_ID
INMUEBLE
INMUEBLE_ID>44</INMUEBLE_ID
INMUEBLE_TIPO>casa</INMUEBLE_TIPO
INMUEBLE_VALOR>37000000</INMUEBLE_VALOR
/INMUEBLE
/OPE
/DOC
/DATOS
DATOS NUM_DOC="3791"
NOTARIO_ID>9</NOTARIO_ID
DOC NUM_OBJ="17" NUM_OPE="784" NUM_SUJ="589"
DOCUMENTO_ID>666</DOCUMENTO_ID
OPE
OPERACION_ID>3036</OPERACION_ID
INMUEBLE
INMUEBLE_ID>99</INMUEBLE_ID
INMUEBLE_TIPO>piso</INMUEBLE_TIPO
INMUEBLE_VALOR>46000000</INMUEBLE_VALOR
/INMUEBLE
/OPE
/DOC
/DATOS
/IND_UNICO


And this is the XSD file:

?xml version="1.0" encoding="UTF-8"?

xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema"
version="2.1.3"

xsd:annotation
xsd:appinfo
sql:relationship
name="INDICE_DATOS"
parent="tblINDICE"
parent-key="idIndice"
child="tblDATOS"
child-key="idIndice"
/
sql:relationship
name="DATOS_DOCUMENTOS"
parent="tblDATOS"
parent-key="idDatos"
child="tblDOCUMENTOS"
child-key="idDatos"
/
sql:relationship
name="DOCUMENTOS_OPERACIONES"
parent="tblDOCUMENTOS"
parent-key="idDocumento"
child="tblOPERACIONES"
child-key="idDocumento"
/
sql:relationship
name="OPERACIONES_INMUEBLES"
parent="tblOPERACIONES"
parent-key="idOperacion"
child="tblINMUEBLES"
child-key="idOperacion"
/
/xsd:appinfo
/xsd:annotation


xsd:element name="IND_UNICO" sql:relation="tblINDICE"
xsd:complexType
xsd:sequence
xsd:element name="DATOS" maxOccurs="unbounded"
sql:relation="tblDATOS"
sql:relationship="INDICE_DATOS"
xsd:complexType
xsd:sequence
xsd:element name="DOC"
sql:relation="tblDOCUMENTOS"
sql:relationship="DATOS_DOCUMENTOS"
xsd:complexType
xsd:sequence
xsd:element name="OPE"
sql:relation="tblOPERACIONES"

sql:relationship="DOCUMENTOS_OPERACIONES"
xsd:complexType
xsd:sequence
xsd:element name="INMUEBLE"
sql:relation="tblINMUEBLES"

sql:relationship="OPERACIONES_INMUEBLES"
xsd:complexType
xsd:sequence
xsd:element name="INMUEBLE_ID"

type="xsd:short"/
xsd:element name="INMUEBLE_TIPO"

type="xsd:string"/
xsd:element name="INMUEBLE_VALOR"

type="xsd:string"/
/xsd:sequence
/xsd:complexType
/xsd:element
xsd:element name="OPERACION_ID"

type="xsd:short"/
/xsd:sequence
/xsd:complexType
/xsd:element
xsd:element name="DOCUMENTO_ID"

type="xsd:short"/
/xsd:sequence
xsd:attribute name="NUM_OBJ" type="xsd:short"
use="required"/
xsd:attribute name="NUM_OPE" type="xsd:short"
use="required"/
xsd:attribute name="NUM_SUJ" type="xsd:short"
use="required"/
/xsd:complexType
/xsd:element
xsd:element name="NOTARIO_ID" type="xsd:short"/
/xsd:sequence
xsd:attribute name="NUM_DOC" type="xsd:short" use="required"/
/xsd:complexType
/xsd:element
/xsd:sequence
xsd:attribute name="schemaVersion" type="xsd:short"
use="required"/
/xsd:complexType
/xsd:element
/xsd:schema



Greetings,
David Grant



Reply With Quote
  #3  
Old   
David Grant
 
Posts: n/a

Default Re: How can XML Bulk Load assign automatically a PK to a column? - 03-07-2005 , 04:51 PM



Thank you for answering, Darren.

I let the XML Bulk Load to create the tables from scratch
because if I create them on my own and I assign the primary
key to a field I begin to receive a lot of errors about
NULL values (MS SQL Server complains about not being able
to insert nulls on the PK/FK fields).

Actually this .XSD file creates 5 tables from scratch:
tblINDICE
tblDATOS
tblDOCUMENTOS
tblOPERACIONES
tblINMUEBLES

and the columns are filled with the right values except for
those which are supposed to become the PK/FK (all the
parent-key/ child-key fields)

These PK/FK fiels are those defined in the sql:relationship
statement which, as it can be seen, start with the prefix
id. Unfortunately, with this Schema, XML Bulk Load only
fills these parent-key and child-key fields with NULL
values instead of the proper indexes. I guess I am doing
something wrong but after reviewing all the info at the
MSDN library, can't discover the source of this issue.

Do you (or anybody else) know an instruction to set a field
either as a PK or a FK from the XSD file?
I'd also be interested in knowing a way to avoid the NULL
autofilling of these PK/FK fields.


Thank you from beforehand,
David Grant



Quote:
-----Original Message-----
The table is not created by the bulk load tool is it? From
memory it isn't so I would expect you to have created the
PK >in advance. I don't think a load should change the
structure, >just the data.
Quote:


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.