SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Views based on Multiple tables causing Locks?


Views based on Multiple tables causing Locks?

Author
Message
ash.blair
ash.blair
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 4
Hi, I have recently started at a new company and the way they have some data set up is as follows:
DatabaseArchive.Table_1
DatabaseArchive.Table_2
DatabaseArchive.Table_3
...
DatabaseArchive.Table_100
DatabaseArchive.Table_101
DatabaseArchive.Table_102


Then in a separate Database the following:
DatabaseDW.Table_103
DatabaseDW.Table_104
DatabaseDW.Table_105.

In the DW database there are two views:
View1 comprised of union of all tables in both databases :
SELECT * FROM DatabaseArchive.Table_1
Union
SELECT * FROM DatabaseArchive.Table_2
..
Union
SELECT * FROM DatabaseDW.Table_104
Union
SELECT * FROM DatabaseDW.Table_105.

View 2 is just the tables in the DW database:
SELECT * FROM DatabaseDW.Table_104
Union
SELECT * FROM DatabaseDW.Table_104
Union
SELECT * FROM DatabaseDW.Table_105.

My question is that if I do any work on any table in the Archive DB say DatabaseArchive.Table_3 will it lead to any locks on the DW tables (say DatabaseDW.Table_104 )due to the fact there are 2 views which use the same tables and thus intersect?
John Mitchell-245523
John Mitchell-245523
SSC Guru
SSC Guru (133K reputation)SSC Guru (133K reputation)SSC Guru (133K reputation)SSC Guru (133K reputation)SSC Guru (133K reputation)SSC Guru (133K reputation)SSC Guru (133K reputation)SSC Guru (133K reputation)

Group: General Forum Members
Points: 133640 Visits: 19401
No, the locks don't cascade up to the views and back down to the other tables referenced by the views. If you do something to a table, you'll get locks on that table only. (There are exceptions to that, for example when it comes to triggers and foreign key constraints, but I don't think that's what you're asking.)

John
ScottPletcher
ScottPletcher
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85821 Visits: 9647
Btw, you might want to seriously consider using "UNION ALL" there rather than UNION. I think you are going to force a massive sort of all the rows by using "UNION".

SQL DBA,SQL Server MVP(07, 08, 09) Prosecutor James Blackburn, in closing argument in the Fatal Vision murders trial:
If in the future, you should cry a tear, cry one for them [the murder victims]. If in the future, you should say a prayer, say one for them. And if in the future, you should light a candle, light one for them.
ash.blair
ash.blair
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 4
Sorry it is UNION ALL, that was me just being lazy in typing up the question. Thanks for the help.
Subramaniam Chandrasekar
Subramaniam Chandrasekar
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3582 Visits: 531
ash.blair - Friday, February 2, 2018 8:39 AM
Sorry it is UNION ALL, that was me just being lazy in typing up the question. Thanks for the help.

I hope our experts had answered your queries, besides if you're facing performance issues while retrieving the data from the tables OR while querying views,you could go for Indexed views. Please make sure the underlying tables are normalized , as you mentioned these are archive tables.

GilaMonster
GilaMonster
SSC Guru
SSC Guru (911K reputation)SSC Guru (911K reputation)SSC Guru (911K reputation)SSC Guru (911K reputation)SSC Guru (911K reputation)SSC Guru (911K reputation)SSC Guru (911K reputation)SSC Guru (911K reputation)

Group: General Forum Members
Points: 911172 Visits: 48847
subramaniam.chandrasekar - Monday, February 5, 2018 1:10 AM
ash.blair - Friday, February 2, 2018 8:39 AM
Sorry it is UNION ALL, that was me just being lazy in typing up the question. Thanks for the help.

besides if you're facing performance issues while retrieving the data from the tables OR while querying views,you could go for Indexed views.

UNION/UNION ALL are not permitted in indexed views, and even if it were, since these views are just combining a bunch of tables, an indexed view would likely not be helpful, and would take up a lot of space.


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search