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


Schema binding across multiple databases


Schema binding across multiple databases

Author
Message
vinothraj
vinothraj
Mr or Mrs. 500
Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)

Group: General Forum Members
Points: 567 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
PaulB-TheOneAndOnly
PaulB-TheOneAndOnly
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23349 Visits: 4639
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.
vinothraj
vinothraj
Mr or Mrs. 500
Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)

Group: General Forum Members
Points: 567 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?
PaulB-TheOneAndOnly
PaulB-TheOneAndOnly
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23349 Visits: 4639
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(BOOKMARKSad[Bmk1000]), OBJECTSad[pubs].[dbo].[employee])) 1 3 1 Bookmark Lookup Bookmark Lookup BOOKMARKSad[Bmk1000]), OBJECTSad[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(OBJECTSad[pubs].[dbo].[employee].[PK_emp_id]), SEEKSad[employee].[emp_id]='JYL26161F') ORDERED FORWARD) 1 4 3 Index Seek Index Seek OBJECTSad[pubs].[dbo].[employee].[PK_emp_id]), SEEKSad[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.
vinothraj
vinothraj
Mr or Mrs. 500
Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)

Group: General Forum Members
Points: 567 Visits: 82
I've already used like that, but i need it across databases.
Steve Jones
Steve Jones
SSC Guru
SSC Guru (223K reputation)SSC Guru (223K reputation)SSC Guru (223K reputation)SSC Guru (223K reputation)SSC Guru (223K reputation)SSC Guru (223K reputation)SSC Guru (223K reputation)SSC Guru (223K reputation)

Group: Administrators
Points: 223692 Visits: 19628
distributed partitioned views?

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
PaulB-TheOneAndOnly
PaulB-TheOneAndOnly
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23349 Visits: 4639
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.
vinothraj
vinothraj
Mr or Mrs. 500
Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)

Group: General Forum Members
Points: 567 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.
PaulB-TheOneAndOnly
PaulB-TheOneAndOnly
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23349 Visits: 4639
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.
andre.quitta
andre.quitta
Say Hey Kid
Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)

Group: General Forum Members
Points: 695 Visits: 403
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
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