您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 本溪分类信息网,免费分类信息发布

获得XML格式的SQLServer图表结构

2024/2/26 0:39:17发布23次查看
程序员经常问我在sql server (windows平台上强大的数据库平台) 2000中是否有内置的存储过程, 将图表结构以xml (标准化越来越近了) 格式返回。 如果前端或中间层的代码将数据转给xml (标准化越来越近了) 格式的存储过程。类似下面的图表结构将会比较有用: o
程序员经常问我在sql server(windows平台上强大的数据库平台) 2000中是否有内置的存储过程, 将图表结构以xml(标准化越来越近了)格式返回。
如果前端或中间层的代码将数据转给xml(标准化越来越近了)格式的存储过程。类似下面的图表结构将会比较有用:
一旦程序员拥有图表的xml(标准化越来越近了)框架, 他们就可定义传到存储过程的xml(标准化越来越近了)字符串的属性和元素的同样名称。这样通过openxml(标准化越来越近了)函数来编写存储过程就很简单了---你不需要再要了解前端xml(标准化越来越近了)的属性和元素如何被映射到特定图表的列名了。
不幸的是, 没有内置的存储过程可以返还图表的xml(标准化越来越近了)框架。但开发一个不难。特定图表中的列名可以通过查寻syscolumns系统图表,information_schema.columns的view,或执行sp_columns系统存储过程获得。这篇文章中我用的是information_schema.columns, 因为微软推荐information_schema view而不是系统图表。注意存储过程只接受两个参数:图表名和拥有者名称, 这是必要的。 因为在一个数据库中多个用户可以拥有同样名称的图表。如果你不指定数据库的拥有者, 存储过程将会假设你需要建立一个数据库本身拥有的图表。
create procedure dbo.get_table_xml(标准化越来越近了)_structure (
@table_name varchar(255),
@owner_name varchar(30) = 'dbo'
)
as
set nocount on
/* table variable to hold values */
declare @temp table (
string_value varchar(4000)
 )
/* check if the table exists */
if not exists (
select a.name
from sysobjects a inner join sysusers b
on a.uid = b.uid
and a.type = 'u'
and a.name = @table_name
and b.name = @owner_name)
begin
raiserror('incorrect table name specified, try again', 16,
1)
return
end
insert @temp
select ''
/* append a few blank spaces to make the output readable */
insert @temp
select ' ' + ' + '/>'
from information_schema.columns
where
table_name = @table_name
and
table_schema = @owner_name
order by ordinal_position
insert @temp
select '
一旦存储过程生成, 你可以按以下方式执行:
exec get_table_xml(标准化越来越近了)_structure 'orders', 'dbo'
本溪分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录