 |
|
 |
|
Next: SQL Server Management Studio
|
| Author |
Message |
External

Since: Oct 24, 2005 Posts: 6
|
(Msg. 1) Posted: Mon Oct 24, 2005 7:33 am
Post subject: SQLXML for xml explicit Archived from groups: microsoft>public>sqlserver>xml (more info?)
|
|
|
Hi ppl,
I am a newbie,a rookie in to the database world.I've got my first job now
in a small company who couldnt offord a full fledged DBA.
We have a requirement in which we need to query a lot of tables and form
numerous XML with those data.
I succeeded in completing the query for sample format by using for xml
explicit ( sql server 2000).
i had to make three select statements and union all to create the universal
table.
Well i was proud of myself.untill the client called.
He dropped the bomb shell that we need to generate a big XML with lots of
child parent.... and on seeing the query that i've written started talking
abt the performance issues..... and has asked me to prepare a doc to give
the various options available and analysing each and choosing the best.
so My question to all you ppl is that what performance issues would i face
in using for XML explicit and how do i overcome it..
is there someother efficent way to get XMl out of the database...
here is the query that i wrote..( i may be needed to have 7 selects and say
10 or more Xmls are to be generated )
SELECT
1 AS tag,
0 AS parent,
y.coursetype AS [X!1!type],
x.coursetitle AS [X!1!coursetitle],
x.courseid AS [X!1!courseid],
y.curriculumid AS [X!1!curriculumid],
y.coursehelptext AS [X!1!helptext],
y.mastery AS [X!1!mastery],
null AS [Y!2!type],
null AS [Y!2!name],
null AS [Y!2!helptext],
null AS [Z!3!type],
null AS [Z!3!name],
null AS [Z!3!location],
null AS [Z!3!active],
null AS [Z!3!duration],
null AS [Z!3!objective],
null AS [Y!2!lessonid!hide],
null AS [Z!3!topicid!hide]
FROM
X x,
Y y
WHERE
x.courseid=y.courseid
UNION ALL
SELECT
2,
1,
y.coursetype,
x.coursetitle ,
x.courseid,
y.curriculumid,
y.coursehelptext,
y.mastery,
z.lessontype,
z.lessonname ,
z.lessonhelptext,
null,
null,
null,
null,
null,
null,
z.lessonid,
null
FROM
X x,
Y y,
Z z
WHERE
x.courseid = y.courseid AND
z.courseid = x.courseid
UNION ALL
SELECT
3,
2,
y.coursetype,
x.coursetitle ,
x.courseid,
y.curriculumid,
y.coursehelptext,
y.mastery,
z.lessontype ,
z.lessonname ,
z.lessonhelptext ,
a.topicquiztype,
a.topicquizname,
a.quizlocation,
a.active,
a.topicquizobjective,
a.topicquizduration,
z.lessonid,
a.topicquizid
FROM
X x,
Y y,
Z z,
A a
WHERE
x.courseid = y.courseid AND
z.courseid = x.courseid AND
a.courseid = x.courseid AND
a.lessonid = z.lessonid
ORDER BY [X!1!courseid],[Y!node!2!lessonid!hide],[Z!3!topicid!hide]
FOR XML EXPLICIT
waiting eagerly ( scratching my head),
toby >> Stay informed about: SQLXML for xml explicit |
|
| Back to top |
|
 |  |
External

Since: Mar 31, 2004 Posts: 22
|
(Msg. 2) Posted: Mon Oct 24, 2005 6:47 pm
Post subject: Re: SQLXML for xml explicit [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
To make a FOR XML EXPLICIT query to perform the best you could create enough
indexes on the tables so that ORDER BY does not result in a SORT in the
query plan and the indexes are used by Query Processor to implement UNION
ALLs as MERGE UNIONs.
As you can see this is not a FOR XML specific advice and the general
indexing trade-off between query performance, DML performance and data size
should be applied.
Best regards,
Eugene
---
This posting is provided "AS IS" with no warranties, and confers no rights.
"Toby" wrote in message
> Hi ppl,
> I am a newbie,a rookie in to the database world.I've got my first job now
> in a small company who couldnt offord a full fledged DBA.
> We have a requirement in which we need to query a lot of tables and form
> numerous XML with those data.
> I succeeded in completing the query for sample format by using for xml
> explicit ( sql server 2000).
> i had to make three select statements and union all to create the
> universal
> table.
>
> Well i was proud of myself.untill the client called.
> He dropped the bomb shell that we need to generate a big XML with lots of
> child parent.... and on seeing the query that i've written started talking
> abt the performance issues..... and has asked me to prepare a doc to give
> the various options available and analysing each and choosing the best.
>
> so My question to all you ppl is that what performance issues would i face
> in using for XML explicit and how do i overcome it..
>
> is there someother efficent way to get XMl out of the database...
>
>
> here is the query that i wrote..( i may be needed to have 7 selects and
> say
> 10 or more Xmls are to be generated )
>
> SELECT
> 1 AS tag,
> 0 AS parent,
> y.coursetype AS [X!1!type],
> x.coursetitle AS [X!1!coursetitle],
> x.courseid AS [X!1!courseid],
> y.curriculumid AS [X!1!curriculumid],
> y.coursehelptext AS [X!1!helptext],
> y.mastery AS [X!1!mastery],
> null AS [Y!2!type],
> null AS [Y!2!name],
> null AS [Y!2!helptext],
> null AS [Z!3!type],
> null AS [Z!3!name],
> null AS [Z!3!location],
> null AS [Z!3!active],
> null AS [Z!3!duration],
> null AS [Z!3!objective],
> null AS [Y!2!lessonid!hide],
> null AS [Z!3!topicid!hide]
> FROM
> X x,
> Y y
>
> WHERE
> x.courseid=y.courseid
>
> UNION ALL
>
> SELECT
> 2,
> 1,
> y.coursetype,
> x.coursetitle ,
> x.courseid,
> y.curriculumid,
> y.coursehelptext,
> y.mastery,
> z.lessontype,
> z.lessonname ,
> z.lessonhelptext,
> null,
> null,
> null,
> null,
> null,
> null,
> z.lessonid,
> null
>
> FROM
> X x,
> Y y,
> Z z
>
> WHERE
> x.courseid = y.courseid AND
> z.courseid = x.courseid
>
>
> UNION ALL
>
> SELECT
> 3,
> 2,
> y.coursetype,
> x.coursetitle ,
> x.courseid,
> y.curriculumid,
> y.coursehelptext,
> y.mastery,
> z.lessontype ,
> z.lessonname ,
> z.lessonhelptext ,
> a.topicquiztype,
> a.topicquizname,
> a.quizlocation,
> a.active,
> a.topicquizobjective,
> a.topicquizduration,
> z.lessonid,
> a.topicquizid
>
>
> FROM
> X x,
> Y y,
> Z z,
> A a
>
> WHERE
> x.courseid = y.courseid AND
> z.courseid = x.courseid AND
> a.courseid = x.courseid AND
> a.lessonid = z.lessonid
>
>
> ORDER BY [X!1!courseid],[Y!node!2!lessonid!hide],[Z!3!topicid!hide]
>
> FOR XML EXPLICIT
>
> waiting eagerly ( scratching my head),
> toby
>
>
>
>
>
> >> Stay informed about: SQLXML for xml explicit |
|
| Back to top |
|
 |  |
External

Since: Jan 21, 2004 Posts: 497
|
(Msg. 3) Posted: Mon Oct 24, 2005 8:52 pm
Post subject: Re: SQLXML for xml explicit [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In addition to Eugene's recommendation, I would also like to point out what
performance issues you have to compare against the alternative of doing the
XML-ification on the client:
Unless some of the XML that you need is static (such so-called wrapper
elements such as the root element or the orders element containing all order
elements), doing the joins and unions on the server normally is better since
it avoids multiple client-server roundtrips, joins can be optimized by the
server optimizer and less data may be transported between the server and the
client.
Best regards
Michael
"Eugene Kogan [MSFT]" wrote in message
> To make a FOR XML EXPLICIT query to perform the best you could create
> enough indexes on the tables so that ORDER BY does not result in a SORT in
> the query plan and the indexes are used by Query Processor to implement
> UNION ALLs as MERGE UNIONs.
> As you can see this is not a FOR XML specific advice and the general
> indexing trade-off between query performance, DML performance and data
> size should be applied.
>
> Best regards,
> Eugene
> ---
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> "Toby" wrote in message
>
>> Hi ppl,
>> I am a newbie,a rookie in to the database world.I've got my first job now
>> in a small company who couldnt offord a full fledged DBA.
>> We have a requirement in which we need to query a lot of tables and form
>> numerous XML with those data.
>> I succeeded in completing the query for sample format by using for xml
>> explicit ( sql server 2000).
>> i had to make three select statements and union all to create the
>> universal
>> table.
>>
>> Well i was proud of myself.untill the client called.
>> He dropped the bomb shell that we need to generate a big XML with lots of
>> child parent.... and on seeing the query that i've written started
>> talking
>> abt the performance issues..... and has asked me to prepare a doc to
>> give
>> the various options available and analysing each and choosing the best.
>>
>> so My question to all you ppl is that what performance issues would i
>> face
>> in using for XML explicit and how do i overcome it..
>>
>> is there someother efficent way to get XMl out of the database...
>>
>>
>> here is the query that i wrote..( i may be needed to have 7 selects and
>> say
>> 10 or more Xmls are to be generated )
>>
>> SELECT
>> 1 AS tag,
>> 0 AS parent,
>> y.coursetype AS [X!1!type],
>> x.coursetitle AS [X!1!coursetitle],
>> x.courseid AS [X!1!courseid],
>> y.curriculumid AS [X!1!curriculumid],
>> y.coursehelptext AS [X!1!helptext],
>> y.mastery AS [X!1!mastery],
>> null AS [Y!2!type],
>> null AS [Y!2!name],
>> null AS [Y!2!helptext],
>> null AS [Z!3!type],
>> null AS [Z!3!name],
>> null AS [Z!3!location],
>> null AS [Z!3!active],
>> null AS [Z!3!duration],
>> null AS [Z!3!objective],
>> null AS [Y!2!lessonid!hide],
>> null AS [Z!3!topicid!hide]
>> FROM
>> X x,
>> Y y
>>
>> WHERE
>> x.courseid=y.courseid
>>
>> UNION ALL
>>
>> SELECT
>> 2,
>> 1,
>> y.coursetype,
>> x.coursetitle ,
>> x.courseid,
>> y.curriculumid,
>> y.coursehelptext,
>> y.mastery,
>> z.lessontype,
>> z.lessonname ,
>> z.lessonhelptext,
>> null,
>> null,
>> null,
>> null,
>> null,
>> null,
>> z.lessonid,
>> null
>>
>> FROM
>> X x,
>> Y y,
>> Z z
>>
>> WHERE
>> x.courseid = y.courseid AND
>> z.courseid = x.courseid
>>
>>
>> UNION ALL
>>
>> SELECT
>> 3,
>> 2,
>> y.coursetype,
>> x.coursetitle ,
>> x.courseid,
>> y.curriculumid,
>> y.coursehelptext,
>> y.mastery,
>> z.lessontype ,
>> z.lessonname ,
>> z.lessonhelptext ,
>> a.topicquiztype,
>> a.topicquizname,
>> a.quizlocation,
>> a.active,
>> a.topicquizobjective,
>> a.topicquizduration,
>> z.lessonid,
>> a.topicquizid
>>
>>
>> FROM
>> X x,
>> Y y,
>> Z z,
>> A a
>>
>> WHERE
>> x.courseid = y.courseid AND
>> z.courseid = x.courseid AND
>> a.courseid = x.courseid AND
>> a.lessonid = z.lessonid
>>
>>
>> ORDER BY [X!1!courseid],[Y!node!2!lessonid!hide],[Z!3!topicid!hide]
>>
>> FOR XML EXPLICIT
>>
>> waiting eagerly ( scratching my head),
>> toby
>>
>>
>>
>>
>>
>>
>
> >> Stay informed about: SQLXML for xml explicit |
|
| Back to top |
|
 |  |
External

Since: Oct 24, 2005 Posts: 6
|
(Msg. 4) Posted: Mon Oct 24, 2005 10:25 pm
Post subject: Re: SQLXML for xml explicit [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Thanks michael and eugene. Yes i would add indexes to the table.
i'd be given a course id..
from that i'd be required to generate a xml for that course
containing lesson details..
then from those lessonids i need to form another xml containing topic ids.
then from those topic ids i need to form another xml containing page details..
So as you see that would be a lot of XML say 20 or more ..
as you can see it would result in executing the complex 'FOR XML EXPLICIT'
everytime i need to generate the XML (20 times).
once this is done the process gets over.
If I am going to use the sql server 2000's 'FOR XML EXPLICIT' it'd take some
time.
So Is this the best way to go for such a requirement. OR should the
developers (Java  ) develop a code to generate their own XML.
or Is there any other efficient way to do. ( oh no dont say 2005 we wont be
able to upgrade at this point of time)..
waiting eagerly for ur invaluable suggestions,
toby
"Michael Rys [MSFT]" wrote:
> In addition to Eugene's recommendation, I would also like to point out what
> performance issues you have to compare against the alternative of doing the
> XML-ification on the client:
>
> Unless some of the XML that you need is static (such so-called wrapper
> elements such as the root element or the orders element containing all order
> elements), doing the joins and unions on the server normally is better since
> it avoids multiple client-server roundtrips, joins can be optimized by the
> server optimizer and less data may be transported between the server and the
> client.
>
> Best regards
> Michael
>
> "Eugene Kogan [MSFT]" wrote in message
>
> > To make a FOR XML EXPLICIT query to perform the best you could create
> > enough indexes on the tables so that ORDER BY does not result in a SORT in
> > the query plan and the indexes are used by Query Processor to implement
> > UNION ALLs as MERGE UNIONs.
> > As you can see this is not a FOR XML specific advice and the general
> > indexing trade-off between query performance, DML performance and data
> > size should be applied.
> >
> > Best regards,
> > Eugene
> > ---
> >> SELECT
> >> 1 AS tag,
> >> 0 AS parent,
> >> y.coursetype AS [X!1!type],
> >> x.coursetitle AS [X!1!coursetitle],
> >> x.courseid AS [X!1!courseid],
> >> y.curriculumid AS [X!1!curriculumid],
> >> y.coursehelptext AS [X!1!helptext],
> >> y.mastery AS [X!1!mastery],
> >> null AS [Y!2!type],
> >> null AS [Y!2!name],
> >> null AS [Y!2!helptext],
> >> null AS [Z!3!type],
> >> null AS [Z!3!name],
> >> null AS [Z!3!location],
> >> null AS [Z!3!active],
> >> null AS [Z!3!duration],
> >> null AS [Z!3!objective],
> >> null AS [Y!2!lessonid!hide],
> >> null AS [Z!3!topicid!hide]
> >> FROM
> >> X x,
> >> Y y
> >>
> >> WHERE
> >> x.courseid=y.courseid
> >>
> >> UNION ALL
> >>
> >> SELECT
> >> 2,
> >> 1,
> >> y.coursetype,
> >> x.coursetitle ,
> >> x.courseid,
> >> y.curriculumid,
> >> y.coursehelptext,
> >> y.mastery,
> >> z.lessontype,
> >> z.lessonname ,
> >> z.lessonhelptext,
> >> null,
> >> null,
> >> null,
> >> null,
> >> null,
> >> null,
> >> z.lessonid,
> >> null
> >>
> >> FROM
> >> X x,
> >> Y y,
> >> Z z
> >>
> >> WHERE
> >> x.courseid = y.courseid AND
> >> z.courseid = x.courseid
> >>
> >>
> >> UNION ALL
> >>
> >> SELECT
> >> 3,
> >> 2,
> >> y.coursetype,
> >> x.coursetitle ,
> >> x.courseid,
> >> y.curriculumid,
> >> y.coursehelptext,
> >> y.mastery,
> >> z.lessontype ,
> >> z.lessonname ,
> >> z.lessonhelptext ,
> >> a.topicquiztype,
> >> a.topicquizname,
> >> a.quizlocation,
> >> a.active,
> >> a.topicquizobjective,
> >> a.topicquizduration,
> >> z.lessonid,
> >> a.topicquizid
> >>
> >>
> >> FROM
> >> X x,
> >> Y y,
> >> Z z,
> >> A a
> >>
> >> WHERE
> >> x.courseid = y.courseid AND
> >> z.courseid = x.courseid AND
> >> a.courseid = x.courseid AND
> >> a.lessonid = z.lessonid
> >>
> >>
> >> ORDER BY [X!1!courseid],[Y!node!2!lessonid!hide],[Z!3!topicid!hide]
> >>
> >> FOR XML EXPLICIT
> >>
> >> waiting eagerly ( scratching my head),
> >> toby >> Stay informed about: SQLXML for xml explicit |
|
| Back to top |
|
 |  |
External

Since: Jan 21, 2004 Posts: 497
|
(Msg. 5) Posted: Sat Oct 29, 2005 1:50 pm
Post subject: Re: SQLXML for xml explicit [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In most cases using FOR XML EXPLICIT will transport less data from the
server to the client and will perform better joins than doing it in Java
code. You can either return everything in a single XML document, or do one
per lesson details, topics, page details (and use joins).
Best regards
Michael
"Toby" wrote in message
> Thanks michael and eugene. Yes i would add indexes to the table.
>
> i'd be given a course id..
> from that i'd be required to generate a xml for that course
> containing lesson details..
>
> then from those lessonids i need to form another xml containing topic ids.
>
> then from those topic ids i need to form another xml containing page
> details..
>
> So as you see that would be a lot of XML say 20 or more ..
>
> as you can see it would result in executing the complex 'FOR XML EXPLICIT'
> everytime i need to generate the XML (20 times).
> once this is done the process gets over.
>
> If I am going to use the sql server 2000's 'FOR XML EXPLICIT' it'd take
> some
> time.
>
> So Is this the best way to go for such a requirement. OR should the
> developers (Java ) develop a code to generate their own XML.
>
> or Is there any other efficient way to do. ( oh no dont say 2005 we wont
> be
> able to upgrade at this point of time)..
>
>
>
> waiting eagerly for ur invaluable suggestions,
> toby
>
>
>
>
> "Michael Rys [MSFT]" wrote:
>
>> In addition to Eugene's recommendation, I would also like to point out
>> what
>> performance issues you have to compare against the alternative of doing
>> the
>> XML-ification on the client:
>>
>> Unless some of the XML that you need is static (such so-called wrapper
>> elements such as the root element or the orders element containing all
>> order
>> elements), doing the joins and unions on the server normally is better
>> since
>> it avoids multiple client-server roundtrips, joins can be optimized by
>> the
>> server optimizer and less data may be transported between the server and
>> the
>> client.
>>
>> Best regards
>> Michael
>>
>> "Eugene Kogan [MSFT]" wrote in message
>>
>> > To make a FOR XML EXPLICIT query to perform the best you could create
>> > enough indexes on the tables so that ORDER BY does not result in a SORT
>> > in
>> > the query plan and the indexes are used by Query Processor to implement
>> > UNION ALLs as MERGE UNIONs.
>> > As you can see this is not a FOR XML specific advice and the general
>> > indexing trade-off between query performance, DML performance and data
>> > size should be applied.
>> >
>> > Best regards,
>> > Eugene
>> > ---
>> >> SELECT
>> >> 1 AS tag,
>> >> 0 AS parent,
>> >> y.coursetype AS [X!1!type],
>> >> x.coursetitle AS [X!1!coursetitle],
>> >> x.courseid AS [X!1!courseid],
>> >> y.curriculumid AS [X!1!curriculumid],
>> >> y.coursehelptext AS [X!1!helptext],
>> >> y.mastery AS [X!1!mastery],
>> >> null AS [Y!2!type],
>> >> null AS [Y!2!name],
>> >> null AS [Y!2!helptext],
>> >> null AS [Z!3!type],
>> >> null AS [Z!3!name],
>> >> null AS [Z!3!location],
>> >> null AS [Z!3!active],
>> >> null AS [Z!3!duration],
>> >> null AS [Z!3!objective],
>> >> null AS [Y!2!lessonid!hide],
>> >> null AS [Z!3!topicid!hide]
>> >> FROM
>> >> X x,
>> >> Y y
>> >>
>> >> WHERE
>> >> x.courseid=y.courseid
>> >>
>> >> UNION ALL
>> >>
>> >> SELECT
>> >> 2,
>> >> 1,
>> >> y.coursetype,
>> >> x.coursetitle ,
>> >> x.courseid,
>> >> y.curriculumid,
>> >> y.coursehelptext,
>> >> y.mastery,
>> >> z.lessontype,
>> >> z.lessonname ,
>> >> z.lessonhelptext,
>> >> null,
>> >> null,
>> >> null,
>> >> null,
>> >> null,
>> >> null,
>> >> z.lessonid,
>> >> null
>> >>
>> >> FROM
>> >> X x,
>> >> Y y,
>> >> Z z
>> >>
>> >> WHERE
>> >> x.courseid = y.courseid AND
>> >> z.courseid = x.courseid
>> >>
>> >>
>> >> UNION ALL
>> >>
>> >> SELECT
>> >> 3,
>> >> 2,
>> >> y.coursetype,
>> >> x.coursetitle ,
>> >> x.courseid,
>> >> y.curriculumid,
>> >> y.coursehelptext,
>> >> y.mastery,
>> >> z.lessontype ,
>> >> z.lessonname ,
>> >> z.lessonhelptext ,
>> >> a.topicquiztype,
>> >> a.topicquizname,
>> >> a.quizlocation,
>> >> a.active,
>> >> a.topicquizobjective,
>> >> a.topicquizduration,
>> >> z.lessonid,
>> >> a.topicquizid
>> >>
>> >>
>> >> FROM
>> >> X x,
>> >> Y y,
>> >> Z z,
>> >> A a
>> >>
>> >> WHERE
>> >> x.courseid = y.courseid AND
>> >> z.courseid = x.courseid AND
>> >> a.courseid = x.courseid AND
>> >> a.lessonid = z.lessonid
>> >>
>> >>
>> >> ORDER BY [X!1!courseid],[Y!node!2!lessonid!hide],[Z!3!topicid!hide]
>> >>
>> >> FOR XML EXPLICIT
>> >>
>> >> waiting eagerly ( scratching my head),
>> >> toby
> >> Stay informed about: SQLXML for xml explicit |
|
| Back to top |
|
 |  |
| Related Topics: | 2000 = SQLXML 2005 = ??? (what is SQLXML replaced with in .. - Does anyone know what to use now instead of SQLXML to simply output XML over HTTP? I don't need any WSDL at this stage although it would be nice, just after outputting XML directly from the server over HTTP. Any suggestions and or tutorials would be muc...
FOR EXPLICIT - i don't think the docvmentation covld be more confvsing. Consider: CREATE TABLE MyNewsEntries( gvid vniqveidentifier, title varchar(200), description text, pvbDate datetime,...
Help with FOR XML EXPLICIT - I am try to create an XML doc that is a debit note consisting of many debit items (3 in this example). This is the desired ovtpvt ... <DebitNote> <DebitNoteDocvmentDate>2005-02-13</DebitNoteDocvment...
For XML Explicit - k. I'm going crazy here. I have some for xml explicit sql working (created a test against the adventureworks database) but how can I get the results of this sql into an xml variable. I have tried inserting it into a table variable or setting an xml..
Need help formatting XML using for XML explicit - Hi, Whenever I execvte the following: select 1 as tag,nvll as parent, '2.0' as [Docvment!1!Version], nvll as [DocvmentBody!2!DocvmentIdentifier], nvll as [DocvmentBody!2!] ... |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|