BDS B/S + SQL Server 2005 XML ( 积分: 200 )

  • 主题发起人 主题发起人 yeschoto21cn
  • 开始时间 开始时间
Y

yeschoto21cn

Unregistered / Unconfirmed
GUEST, unregistred user!
准备使用BDS2006写.Net B/S,使用SQL Server 2005 XML类型字段,刚刚开始,还没有找到头绪,希望大家帮忙一下或一起讨论一下:
1.关于XML建模:我的步骤是:在SQL Server中自带的VS2005,新建XML架构,连接原始数据库(没有XML字段),然后把表拖进去,在查看代码中修改。
2.创建一个带有XML类型字段的表,下一步怎么做?建好的XML架构在新建的库里怎么用?
3.XML类型字段可以做索引或全文索引,以查询一亿条数据来比较,是传统的表快,还是把传统的表转换为XML快?
4.如何用BDS查询/处理/显示XML类型字段的内容?
5.在BDS中怎么处理权限的问题?
...
若哪位DFW有相关的一整套例子/代码(简单的也可),恳请发布共享下,需付RMB的话,亦可商量,邮件:YESchoTo(at)21cn.com
 
经过整理,把原来的多个表整理到一个表中,以方便把数据导入到XML类型的字段中。
CREATE TABLE [dbo].[db_books](
[ID] [int] IDENTITY(1,1) NOT NULL,
[book_id] [int] NULL,
[book_no] [smallint] NULL DEFAULT ((1)),
[book_isbn] [nvarchar](50) NULL,
[book_title] [nvarchar](250) NULL,
[book_author_main] [nvarchar](250) NULL,
[book_author_other] [nvarchar](max) NULL,
[book_intro] [nvarchar](max) NULL,
[book_pages] [float] NULL,
[book_price] [float] NULL,
CONSTRAINT [PK_db_books] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
 
在VS2005中新建XML架构:
1。连接数据库BOOKS
2。新建XML架构,拖动db_books表到中间工作区,查看源代码,COPY。
3。返回数据库引擎,创建XML架构:
create xml schema collection x_books
as
'<?xml version=&quot;1.0&quot;
encoding=&quot;utf-8&quot;?>
<xs:schema targetNamespace=&quot;http://tempuri.org/XMLSchema.xsd&quot;
elementFormDefault=&quot;qualified&quot;
xmlns=&quot;http://tempuri.org/XMLSchema.xsd&quot;
xmlns:mstns=&quot;http://tempuri.org/XMLSchema.xsd&quot;
xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;
xmlns:msdata=&quot;urn:schemas-microsoft-com:xml-msdata&quot;>
<xs:element name=&quot;Document&quot;>
<xs:complexType>
<xs:choice minOccurs=&quot;0&quot;
maxOccurs=&quot;unbounded&quot;>
<xs:element name=&quot;db_books&quot;>
<xs:complexType>
<xs:sequence>
<xs:element name=&quot;ID&quot;
type=&quot;xs:int&quot;
/>
<xs:element name=&quot;book_id&quot;
type=&quot;xs:int&quot;
minOccurs=&quot;0&quot;
/>
<xs:element name=&quot;book_no&quot;
type=&quot;xs:short&quot;
minOccurs=&quot;0&quot;
/>
<xs:element name=&quot;book_isbn&quot;
type=&quot;xs:string&quot;
minOccurs=&quot;0&quot;
/>
<xs:element name=&quot;book_title&quot;
type=&quot;xs:string&quot;
minOccurs=&quot;0&quot;
/>
<xs:element name=&quot;book_author_main&quot;
type=&quot;xs:string&quot;
minOccurs=&quot;0&quot;
/>
<xs:element name=&quot;book_author_other&quot;
type=&quot;xs:string&quot;
minOccurs=&quot;0&quot;
/>
<xs:element name=&quot;book_intro&quot;
type=&quot;xs:string&quot;
minOccurs=&quot;0&quot;
/>
<xs:element name=&quot;book_pages&quot;
type=&quot;xs:double&quot;
minOccurs=&quot;0&quot;
/>
<xs:element name=&quot;book_price&quot;
type=&quot;xs:double&quot;
minOccurs=&quot;0&quot;
/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>'
Go
 
添加XML字段的表并指定XML架构到x_bookx字段(xml(CONTENT dbo.x_books)):
CREATE TABLE [dbo].[x_books](
[id] [int] IDENTITY(1,1) NOT NULL,
[x_book_title] [nvarchar](250) NULL,
[x_bookx] [xml](CONTENT [dbo].[x_books]) NULL,
CONSTRAINT [PK_x_books] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
 
好了,开始把整理好的数据导入新建好的x_books表了,怎么做?大家来帮下忙吧。
 
后退
顶部