Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Schema binding across multiple databases Expand / Collapse
Author
Message
Posted Thursday, September 23, 2010 12:18 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, August 6, 2012 11:00 PM
Points: 219, Visits: 82
Hi All

We need to create a clustered index by implementing schema binding in the view. As you know it throws error. Could anyone possibly tell me to achieve in alternate way?

Thanks in advance
Vin
Post #991752
Posted Thursday, September 23, 2010 7:50 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 8:15 AM
Points: 3,065, Visits: 4,639
vinothraj (9/23/2010)
We need to create a clustered index by implementing schema binding in the view. As you know it throws error.

How could I know? ... post shows nothing.
Would you mind in posting a test case showing the issue?


_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Post #992024
Posted Thursday, September 23, 2010 9:44 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, August 6, 2012 11:00 PM
Points: 219, Visits: 82
Thanks for the reply...

For example i've two databases called "dbFirst" and "dbSecond".

In dbSecond i've a table called "EmployeeTable".

I'm going to create a view called "EmployeeView" in dbFirst database with

Select
EmployeeNumber,
EmployeeName
From
dbSecond.dbo.EmployeeTable

I want to create a index (either clustered or non-clustered) for this view as my view containing millions of records and i dont want to wait for the retrieval. If i want to create index for this view which is located in dbFirst referring dbSecond, i'm unable to do. Could you suggest me whether there is any alternate way to achieve this?
Post #992453
Posted Wednesday, September 29, 2010 6:13 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 8:15 AM
Points: 3,065, Visits: 4,639
vinothraj (9/23/2010)
Select
EmployeeNumber,
EmployeeName
From
dbSecond.dbo.EmployeeTable

I want to create a index (either clustered or non-clustered) for this view as my view containing millions of records and i dont want to wait for the retrieval. If i want to create index for this view which is located in dbFirst referring dbSecond, i'm unable to do. Could you suggest me whether there is any alternate way to achieve this?


First, a view is an abstraction not a physical object meaning a view is just a stored query therefore it can contain nothing.

SQL Server engine takes advantage of the indexes pointing to the base table/s of the view.

You can see it by yourself doing this simple test.

1- Go to Northwind and create a view pointing to Pubs database like...
USE Northwind
go
SET ANSI_NULLS,QUOTED_IDENTIFIER ON
go
CREATE VIEW dbo.MyEmployeeView
AS
SELECT *
FROM pubs.dbo.employee
WHERE emp_id = 'JYL26161F'

2- Check the execution plan of query below...
USE Northwind
go
select *
from dbo.MyEmployeeView

... which should show something like...
StmtText	StmtId	NodeId	Parent	PhysicalOp	LogicalOp	Argument	DefinedValues	EstimateRows	EstimateIO	EstimateCPU	AvgRowSize	TotalSubtreeCost	OutputList	Warnings	Type	Parallel	EstimateExecutions
select * from dbo.MyEmployeeView 1 1 0 [NULL] [NULL] 1 [NULL] 1 [NULL] [NULL] [NULL] 0.0126592 [NULL] [NULL] SELECT 0 [NULL]
|--Bookmark Lookup(BOOKMARK[Bmk1000]), OBJECT[pubs].[dbo].[employee])) 1 3 1 Bookmark Lookup Bookmark Lookup BOOKMARK[Bmk1000]), OBJECT[pubs].[dbo].[employee]) [employee].[hire_date], [employee].[pub_id], [employee].[job_lvl], [employee].[job_id], [employee].[lname], [employee].[minit], [employee].[fname], [employee].[emp_id] 1 0.00625 1.1e-006 49 0.0126592 [employee].[hire_date], [employee].[pub_id], [employee].[job_lvl], [employee].[job_id], [employee].[lname], [employee].[minit], [employee].[fname], [employee].[emp_id] [NULL] PLAN_ROW 0 1
|--Index Seek(OBJECT[pubs].[dbo].[employee].[PK_emp_id]), SEEK[employee].[emp_id]='JYL26161F') ORDERED FORWARD) 1 4 3 Index Seek Index Seek OBJECT[pubs].[dbo].[employee].[PK_emp_id]), SEEK[employee].[emp_id]='JYL26161F') ORDERED FORWARD [Bmk1000] 1 0.0063285 7.96e-005 53 0.0064081 [Bmk1000] [NULL] PLAN_ROW 0 1


... it does takes advantage of existing base table indexes, doesn't it?



_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Post #995119
Posted Wednesday, September 29, 2010 8:15 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, August 6, 2012 11:00 PM
Points: 219, Visits: 82
I've already used like that, but i need it across databases.
Post #995259
Posted Wednesday, September 29, 2010 8:28 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 10:36 AM
Points: 31,362, Visits: 15,823
distributed partitioned views?






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #995283
Posted Wednesday, September 29, 2010 11:42 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 8:15 AM
Points: 3,065, Visits: 4,639
vinothraj (9/29/2010)
I've already used like that, but i need it across databases.


Please note that my example has query and view in database "A" while base tables of the view are in database "B".

Would you mind in elaborating about "across databases"?


_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Post #995462
Posted Wednesday, September 29, 2010 10:27 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, August 6, 2012 11:00 PM
Points: 219, Visits: 82
thanks buddy. you are correct its across databases, where as i need schema binding in view not in table which is my original query.
Post #995733
Posted Thursday, September 30, 2010 6:27 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 8:15 AM
Points: 3,065, Visits: 4,639
vinothraj (9/23/2010)
We need to create a clustered index by implementing schema binding in the view.

Lets start over?

Post is kind of confusing.

1- Clustered indexes have their leaf level inside the target table therefore it is hard to understand how "clustered index" and "view" got into the same phrase.

2- schemabinding option creates a schema - schema as in DDL - dependency in between the new view and the base tables. Again, not sure how "clustered index" made it to this phrase.


_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Post #995860
Posted Monday, December 6, 2010 3:02 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, December 11, 2014 9:25 AM
Points: 105, Visits: 298
While reading this post, I believe I have a similar question. There are tables that exist in dbA and dbB. I wish to create an fast view in dbC, as in the example below:

USE [Onyx_support]
GO

IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vIncident_Audit_Log]'))
DROP VIEW [dbo].[vIncident_Audit_Log]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[vIncident_Audit_Log] WITH SCHEMABINDING
AS
SELECT incident_audit_log_id, site_id, incident_type_did, incident_category_did, incident_product_code, incident_id, secondary_id, assigned_to, labor, time,
primary_contact_id, primary_contact_type_enum, assigned_id, tracking_code_did, serial_number, desc1, desc2, source_did, status_did,
resolution_did1, resolution_did2, resolution_did3, resolution_did4, total_time, total_labor, image, read_only_access, private_access, reminder_date,
user1, user2, user3, user4, user5, user6, user7, user8, user9, user10, insert_by, insert_date, update_by, update_date, onyx_timestamp, delete_status,
central_office, cs_source_description, cs_proposal_date, cs_projected_close_month, cs_contract_expire_date, cs_current_provider, cs_competitor,
cs_competitor_description, cs_pots_ale, cs_t1_ale, cs_mrr, cs_nrr, cs_hi_cap_ale, cs_phone_system_type, cs_bts_nrr
FROM onyx.dbo.incident_audit_log
WHERE (insert_date > DATEADD(m, - 2, GETDATE()))


when I try to run the above code, I get the error below:

Cannot schema bind view 'dbo.vIncident_Audit_Log' because name 'onyx..incident_audit_log'
is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.

Is there a way for me to create an indexable view on a column that is not indexed in the Onyx db? They are proprietary database tables that are running too slow in a query.

TIA
Andre
Post #1030875
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse