473,770 Members | 4,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deadlock in View with Select Union - Creating A/S Dimension

I've got a view that creates a parent child relationship, this view is
used in Analysis Services to create a dimension in a datastore. This
query tends to deadlock after about 10 days of running smoothly. Only
way to fix it is to reboot the box, I can recycle the services for a
quick fix but that usually only works for the next 1-2 times I call the
view.

This view is used to create a breakdown of the bill-to locations from
Continent-Global Region-Country-Sub Region-State/Province- City-Zip
Code

Yes, I know that sounds crazy, but it was a requirement.

So why would I get a deadlock on a SELECT Query? Is there a way to set
the Isolation level to Repeatable Read for a view?

Here is the view code:

CREATE View dbo.vwBillTo
as
-- US ZipCode
Select 'Parent'=z.City +' ('+ ISNULL(RTRIM(z. State_shrt), '0') +
cast(IsNull(z.U S_Region_wk,0) as varchar) + ')'
,z.Zipcode_WK as 'Child'
,z.ZipCode_WK as 'Child_ID'
From dbo.DIM_POSTAL_ CODES_US z
inner join dbo.FACT_SALES f
on z.ZipCode_WK=f. Bill_To
Where z.US_Region_wk IS NOT NULL
Group by z.City,z.ZipCod e_WK,US_Region_ wk, z.State_shrt

Union
--City
Select 'Parent'=z.Stat e_Long+' ('+cast(IsNull( z.US_Region_wk, 0) as
varchar)+')'
,z.City as 'Child'
,z.City + ' ('+ ISNULL(RTRIM(z. State_shrt), '0') +
cast(IsNull(z.U S_Region_wk,0) as varchar) + ')' as 'Child_ID'
From dbo.DIM_POSTAL_ CODES_US z
Where z.US_Region_wk IS NOT NULL
Group by z.State_Long,z. City,z.State_sh rt,z.US_Region_ wk

Union

-- Canada ZipCode
Select 'Parent'=z.City + ' ('+ ISNULL(RTRIM(z. province_shrt), '0') +
')'
,z.Zipcode_WK as 'Child'
,z.Zipcode_WK as 'Child_ID'
From dbo.DIM_POSTAL_ CODES_CAN z
inner join dbo.FACT_SALES f
on z.ZipCode_WK=f. Bill_To
Group by z.Province_Long ,z.ZipCode_WK, z.City, z.province_shrt

Union

--City
Select 'Parent'=z.Prov ince_Long
,z.City as 'Child'
,z.City+ ' ('+ ISNULL(RTRIM(z. province_shrt), '0') + ')' as
'Child_ID'
From dbo.DIM_POSTAL_ CODES_CAN z
inner join dbo.FACT_SALES f
on z.ZipCode_WK=f. Bill_To
Group by z.Province_Long ,z.ZipCode_WK, z.City, z.province_shrt
Union

-- Canada Province
Select 'CANADA'
,Province_Long
,Province_Long
From dbo.DIM_POSTAL_ CODES_CAN
Group by Province_Long

Union
-- Country
Select t.Region_NK
,c.Country_Name
,c.Country_Name
From dbo.DIM_COUNTRY c
Inner Join dbo.DIM_WORLD_R EGION t
On c.Region_WK=t.R egion_WK
Where c.Country_Name Is Not Null
Group by t.Region_NK, c.Country_Name

Union

-- SubRegion
Select c.Country_Name
,sr.US_Region_N ame
,sr.US_Region_N ame
From dbo.DIM_US_REGI ON sr
Inner Join dbo.DIM_COUNTRY c
On sr.Country_wk=c .Country_WK
Group by c.Country_Name, sr.US_Region_Na me

Union
--Region
Select sr.US_Region_Na me
,c.State_Long
,c.State_Long+' ('+cast(c.US_Re gion_wk as varchar)+')'
From dbo.DIM_US_REGI ON sr
Inner Join dbo.DIM_POSTAL_ CODES_US c
On sr.US_Region_WK =c.US_Region_WK
Group by sr.US_Region_Na me, c.State_Long,c. US_Region_wk

Union
-- Continent
Select Null
,Region_NK
,Region_NK
From dbo.DIM_WORLD_R EGION

Where Region_NK Is Not Null

Jul 23 '05 #1
1 3339
(jt******@tycov alves.com) writes:
I've got a view that creates a parent child relationship, this view is
used in Analysis Services to create a dimension in a datastore. This
query tends to deadlock after about 10 days of running smoothly. Only
way to fix it is to reboot the box, I can recycle the services for a
quick fix but that usually only works for the next 1-2 times I call the
view.

This view is used to create a breakdown of the bill-to locations from
Continent-Global Region-Country-Sub Region-State/Province- City-Zip
Code

Yes, I know that sounds crazy, but it was a requirement.

So why would I get a deadlock on a SELECT Query? Is there a way to set
the Isolation level to Repeatable Read for a view?


You can always issue SET TRANSACTION ISOALATION LEVEL prior to running
the SELECT. Not sure that it would help though.

Indeed a deadlock on a single SELECT sounds weird. I know there are
cases where parallelism can lead to deadlock within a single query,
but that would be INSERT/UPDATE/DELETE.

But how do you know that is not interacting with any other query? Have
you enabled trace flag 1204 and checked the error log?
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1445
by: Karen Bailey | last post by:
Hi, I am attempting to create a view that will rollup or group like, consecutive data. I have created a view using unions, but the statement is extremely slow. Here is example data Colour Table:
4
8102
by: MD | last post by:
I am trying to create a dynamic SQL statement to create a view. I have a stored procedure, which based on the parameters passed calls different stored procedures. Each of this sub stored procedure creates a string of custom SQL statement and returns this string back to the main stored procedure. This SQL statements work fine on there own. The SQL returned from the sub stored procedure are returned fine. The datatype of the variable that...
2
2176
by: jc | last post by:
Hi. A question I have is with regard to the use of views with SQL2000. If I have a view called "A_view" and used in the following manner; ---------------- SELECT ... FROM A_View WHERE .... UNION
10
5637
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I create a single View and specify also in this View the WHERE clause that is common in these stored procedures, I will have the new stored procecures changed to be like:
6
4387
by: Eugene | last post by:
Summary: ---------- Updates against UNION ALL view does't do branch elimination, but rather reads all the branches (partitions). The case scenario(DB2 V8.1.4a ESE, AIX 5.2): -------------------------------------------- The UNION ALL view (tv) was built on the following three sample tables (t1,t2,t3)
6
3035
by: _link98 | last post by:
Problem: getting SQL0181N for queries on nicknames to remote Union-All-View. Can't see what I'm doing wrong yet, maybe someone has seen this before. Environment: UDB ESE 8.1 + FIXPAK 9A, on Solaris 8.1, with 64-bit instances. I have a NICKNAME called REMOTE_DW.T_MYTABLE which points to a "union-all-view". Several other nicknames exist to regular-tables and regular views in
104
10900
by: Beowulf | last post by:
I have the view below and if I use vwRouteReference as the rowsource for a combo box in an MS Access form or run "SELECT * FROM vwRouteReference" in SQL Query Analyzer, the rows don't come through sorted by Numb. Everything I've read on the web suggests that including the TOP directive should enable ORDERY BY in views. Does someone have an idea why the sorting is not working correctly for this particular view? thanks. CREATE VIEW...
7
15065
by: jason.langdale | last post by:
I have 3 tables I want to use in a view. Table A has field 1,2,3,4,5 and table B has field 1,2,3,4,5. I want to do a union on these. (I have done so successfully if I stop here) I also want to join table C which has field 1,6,7,8,9. I would like to join on field 1 and bring in the other fields. I can join table C to A or B. I can union table A and B but I do not know how to both union A and B then join C. Can someone please help me? Thanks...
5
4614
by: Altman | last post by:
I have a customer using our program with SQL server and is occasionally getting a "Transaction (process ID xxxxx) was deadlocked on lock resources with another process and has been chosen as the deadlock victim." From what they are telling me, there shouldn't be any deadlock happening as they say this happens when they invoicing in a different program that is accessing a different database. Also the error is happening on an SQL Select...
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.