首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >联合扇出查询

联合扇出查询
EN

Stack Overflow用户
提问于 2012-06-04 21:48:41
回答 2查看 1.4K关注 0票数 1

我是sql azure的新手。现在我面临着一个很大的问题,那就是SQL Azure联合。在我的一个项目中,我想使用联合。为此,我希望从所有联盟读取数据。如何查看服务器中的联盟总数,并从联盟中读取数据?另外,我如何将数据插入到联合中?目前我使用的是:

代码语言:javascript
复制
string strSQL = @"SELECT f.name, fmc.federation_id, fmc.member_id, fmc.range_low, fmc.range_high " +
                                                            "FROM sys.federations f " +
                                                            "JOIN sys.federation_member_distributions fmc " +
                                                            "ON f.federation_id=fmc.federation_id " +
                                                            "ORDER BY fmc.federation_id, fmc.range_low, fmc.range_high";
        string strTableName = "federation_member_distributions";

        try
        {
            using (SqlConnection connection = new SqlConnection(csb.ToString()))
            {
                connection.Open();
                sbResults.AppendFormat("-- Open {0}\r\n\r\n", csb.ToString());

                data = new DataSet();
                data.Locale = System.Globalization.CultureInfo.InvariantCulture;

                using (SqlCommand command = connection.CreateCommand())
                {
                    // Connect to federation root or federation member
                    command.CommandText = "USE FEDERATION ROOT WITH RESET";
                    command.ExecuteNonQuery();
                    sbResults.AppendFormat("{0}\r\nGO\r\n", command.CommandText);
                }

                //Retrieve federation root metadata, and populate the data to the DataGridView control
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(strSQL, connection);
                sqlDataAdapter.Fill(data, strTableName);
                sbResults.AppendFormat("{0}\r\nGO\r\n", strSQL);
            }

        }
        catch (Exception ex)
        {

        }

但是它不起作用。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-06-05 00:28:45

对于上面的问题,你真的需要看看这些关于如何使用SQL Azure Federation的文章:

Introduction to Fan-out Queries for Federations in SQL Azure (Part 1): Scalable Queries over Multiple Federation Members, MapReduce Style!

您可以在上面找到扇出示例工具,其中包含向您展示如何从联盟中获取数据的代码。

此示例的第二部分"Fan-out Querying for Federations in SQL Azure (Part 2): Scalable Fan-out Queries with TOP, ORDER BY, DISTINCT and Other Powerful Aggregates, MapReduce Style!“展示了如何通过特定示例运行扇出查询。

试一下上面的样品,如果你遇到任何问题,请告诉我们。

票数 3
EN

Stack Overflow用户

发布于 2012-06-06 07:08:18

我与SQL Azure团队的Cihan Biyikoglu进行了讨论,以下是他的建议:

这个想法是,您不必缓存数据在联邦中所在位置的“映射”,因此您不应该这样做;

下面是执行扇出的伪应用程序代码和实际示例;您也可以在此UI中试用这些代码。

http://federationsutility-seasia.cloudapp.net/About.aspx

代码语言:javascript
复制
Start at the 
@i=MIN_VALUE (of the data_type or federation key like customerID=-1)
While (@i not null)
{
 Try
 {
    -- switch to the next member
    USE FEDERATION fedname(id=@i)...

    -- Run your transaction here for this member 
    SELECT * FROM table join other_table … WHERE fedkeycolumn >= @i group by … order by …

    -- grab the next value
    SELECT @i=range_high FROM sys.federation_member_distributions 
 }
 Catch ()
 {
           If retry_count < total_retries
                          Exit the loop
 }
}

如果你仍然想要找出成员,你总是可以在包含联邦的数据库中运行查询;

代码语言:javascript
复制
Select * from sys.federation_member_distributions fmd join sys.federations f on fmd.federation_id=f.federation_id 

这种方法的问题是,如果在读取信息和完成查询处理之间存在时间差距,则可能会错过读取数据的时间。

上面没有缓存“map”的方法不容易出现这个问题。它将捕获所有成员,而不管任何重新分区操作。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10882452

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档