SQL 2005对xml文件与xml数据的操作
2010-06-16 15:43:38 来源:WEB开发网-----------------------同时读入多表数据----------------
create table Xmlta(Name nvarchar(20),Nowtime datetime)
create table Xmltb(Name nvarchar(20),Nowtime datetime)
declare @s as nvarchar(4000);
set @s =N'
<Xmltables>
<Xmlta Name="1" Nowtime="1900-2-1">0</Xmlta>
<Xmltb Name="2" Nowtime="1900-2-1">0</Xmltb>
</Xmltables>
';
--<Xmlta ></Xmlta> 则插入的数据为null
declare @idHandle as int ;
EXEC sp_xml_preparedocument @idHandle OUTPUT, @s
--表a
insert into Xmlta(Name,Nowtime)
select * from openxml(@idHandle,N'/Xmltables/Xmlta')
with dbo.Xmlta
--表b
insert into Xmltb(Name,Nowtime)
--生成xml文件单表
select * from openxml(@idHandle,N'/Xmltables/Xmltb')
with dbo.Xmltb
EXEC sp_xml_removedocument @idHandle
select * from Xmlta
select * from Xmltb
drop table Xmlta,Xmltb
DECLARE @xVar XML
SET @xVar = (SELECT * FROM Xmltable FOR XML AUTO,TYPE)
select @xVar
--1读取xml文件插入表中
DECLARE @hdoc int
DECLARE @doc xml
select @doc=BulkColumn from (SELECT *
FROM OPENROWSET(BULK 'E:xml.xml',SINGLE_BLOB) a)b
EXEC sp_xml_preparedocument @hdoc OUTPUT,@doc
SELECT * into #temp
FROM OPENXML (@hdoc,N'/root/dbo.xmltable')
with (name nvarchar(20),Intro nvarchar(20))
exec sp_xml_removedocument @hdoc
--2读取xml文件插入表中
SELECT * into #temp FROM OPENROWSET(
BULK 'E:xml.xml',SINGLE_BLOB) AS x
DECLARE @hdoc int
DECLARE @doc xml
select @doc=BulkColumn from #temp
EXEC sp_xml_preparedocument @hdoc OUTPUT,@doc
SELECT * into #temp2
FROM OPENXML (@hdoc,N'/root/dbo.xmltable')
with (name nvarchar(20),Intro nvarchar(20))
exec sp_xml_removedocument @hdoc
/*
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
- ››sqlserver安装和简单的使用
- ››SQL Sever 2008 R2 数据库管理
- ››SQL SERVER无法安装成功,sqlstp.log文件提示[未发...
- ››Sql Server中通过父记录查找出所有关联的子记录
- ››SqlServer触发器、存储过程和函数
- ››SQL Server 中的事务(含义,属性,管理)
- ››Sqlite数据库插入和读取图片数据
- ››Sql server 2005拒绝了对对象 'xx表' (数...
- ››Sql server 2005拒绝了对对象 'xx表' (数...
更多精彩
赞助商链接