这是在 SQL Server 2008 中存储 XML 数据的好方法吗?
我正在对使用 SQL Server 2008 以以下结构存储数据进行可行性研究:
-MYTABLE
|ID|RECORDS|BRANCH_OFFICE|MONTH|YEAR
RECORDS 列具有 XML 数据类型,它看起来像:
<visits>
<visit id="000112233">
<costumer>Mr. One Costumer</costumer>
<date>2011-02-10</date>
<employee>MAT01234</employee>
</visit>
<visit id="000112234">
<costumer>Mr. Another Costumer</costumer>
<date>2011-02-12</date>
<employee>MAT01235</employee>
</visit>
<visit id="000112235">
<costumer>Mr. Some Costumer</costumer>
<date>2011-02-12</date>
<employee>MAT01234</employee>
</visit>
<visit id="000112236">
<costumer>Mr. Some Costumer</costumer>
<date>2011-02-15</date>
<employee>MAT01235</employee>
</visit>
</visits>
我打算使用 xquery 查询 xml 列,这是一个存储这些数据的好方法?
如果我想获取 2011-10 年间发生的访问列表,添加一个带有“日期”标签与现在之间天数差异的标签,怎么可能呢?
I'm doing a feasibility study for storing data in the following structure with SQL Server 2008:
-MYTABLE
|ID|RECORDS|BRANCH_OFFICE|MONTH|YEAR
The RECORDS column has the XML data type and it will look like:
<visits>
<visit id="000112233">
<costumer>Mr. One Costumer</costumer>
<date>2011-02-10</date>
<employee>MAT01234</employee>
</visit>
<visit id="000112234">
<costumer>Mr. Another Costumer</costumer>
<date>2011-02-12</date>
<employee>MAT01235</employee>
</visit>
<visit id="000112235">
<costumer>Mr. Some Costumer</costumer>
<date>2011-02-12</date>
<employee>MAT01234</employee>
</visit>
<visit id="000112236">
<costumer>Mr. Some Costumer</costumer>
<date>2011-02-15</date>
<employee>MAT01235</employee>
</visit>
</visits>
I'm intending to query the xml column with xquery, is this a good way to store this data?
If I want to get the list of visits occurring in 2011-10, adding a tag with the difference of days between the "date" tag and now, how could it be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
针对您的 XML 的查询可能看起来像这样,我认为您的结构很好。无需执行任何花哨的 XML 操作即可获取所需的信息。
结果:
A query against your XML could look something like this and I think your structure is just fine. There is no need to do any fancy XML stuff to get the information you need.
Result: