Localizing Language/Region-Based Customer Settings

Downloads
96137.zip

Subscribe to SQL Server Magazine UPDATE, a free weekly email newsletter, with exclusive commentary by Brian Moran. Sign up now at http://www.sqlmag.com/email.

Here's the solution to the June Reader Challenge. (To read the full Challenge, "Optimizing Queries for Fact Tables," go to InstantDoc ID 95960.)

Solution:
Mark can't create an index on each of the measure column s in the fact table since such a construction would contain values from all the rows. In addition, since the data in the fact table is sparse, creating such indexes would be inefficient. Instead, he can use indexed views to create smaller indexes and filter the rows based on the non-null value of a particular measurement. For example, he can create an indexed view per measurement that contains only non-null values such as

CREATE VIEW dbo.InstrStats_Msr1
WITH schemabinding
AS
SELECT InstrId, Msr1, CreateTime
FROM dbo.InstrStats
WHERE Msr1 IS NOT NULL
GO

Mark can create a unique clustered index on the view that contains the instrument identification and creation time of the fact table. The following CREATE INDEX statement creates such an index on the InstrStats_Msr1 view:

create unique clustered index
 InstrStats_Msr1_Time on
 dbo.InstrStats_Msr1(InstrId,
 CreateTime desc);
go

The scripts in Web Listing 1 show how to create such indexed views on other measurement columns.

Now the queries from the reports can use the indexed views more efficiently. And if the SQL Server software is Enterprise Edition, the query rewrite happens transparently. You can observe the use of the indexed views for the sample report queries by looking at the show plan output. Figure 1 shows sample output.

JULY CHALLENGE:
Test your SQL Server savvy in this month's Reader Challenge. Submit your solution in an email message to challenge@sqlmag.com by July 19, 2007. A SQL Server Magazine technical editor, will evaluate the responses. We'll announce the winner in an upcoming SQL Server Magazine UPDATE. The first-place winner will receive $100, and the second-place winner will receive $50.

Problem:
Tony is a T-SQL programmer in a company that sells sports products online. He is currently designing the product catalog functionality of a Web-based order placement application. The database is hosted on Microsoft SQL Server 2005. As part of the product catalog display, he wants to localize the description of various products based on the language or regional settings of the customer.

For the purpose of this problem, assume that the product catalog tables are similar to the tables in the sample AdventureWorks database for SQL Server 2005. The tables that can be used for solving the problem are \[Production\].\[Culture\], \[Production\].\[ProductDescription\], \[Production\].\[ProductModel\], \[Production\].\[ProductModelProductDescriptionCulture\] and \[Production\].\[Product\].

The \[Production\].\[ProductModelProductDescriptionCulture\] table contains the mapping between each product model, description, and culture or language stored in the database. For example, it might contain descriptions for certain models for the English language or for the English and Spanish languages.

Using the AdventureWorks database tables I just described, help Tony create an appropriate database object that he can use on the client or server and that returns the following details when a specific culture is chosen:

  1. Product attributes
  2. Product model name
  3. Localized product description (i.e., the description for the specified culture or the description in English when a culture isn't specified)

In addition, Tony needs the flexibility to filter the results based on various product attributes or join with other tables, views, or functions.

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottOur Experts will show you:
• Common SQL Server
Problems
• Best Practices for T-SQL
• SQL Server Integration
Services
• Database Development

Come See Michael Otey & Tim Ford in Person!

Early Registration Now Open

From the Blogs
May 21, 2013
blog

A Common Misconception about MAXDOP

Out of the box, SQL Server is (and has been) able to take advantage of multiple processors/cores without any effort on behalf of administrators....More
May 9, 2013
blog

My ISO 8601-Compliant Signature 2

My family recently just "officially" announced that we're in the process of adopting a child from South Africa. We're quite excited, of course, but there's a ton of paperwork to do—along with the need for gobs of signatures....More
May 8, 2013
blog

Use SSIS for ETL from Hadoop

In this blog post, Mark Kromer walks you through using SSIS as a way to use ETL techniques using Microsoft's Hadoop on Windows (HDInsight) as a source using Hive connectors...More
SQL Server Pro Forums

Get answers to questions, share tips, and engage with the SQL Server community in our Forums.