Announcement

Collapse
No announcement yet.

Index auf View läßt sich nicht erstellen

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Index auf View läßt sich nicht erstellen

    Hallo Leute, ich hab eine relativ komplexe view gebastelt, die die Haupttabelle mit Daten aus mehreren Detailtabellen anreichert. Nun habe ich mir überlegt, dass ein Index auf einer View evtl. die Abfragegeschwindigkeit erhöhen könnte. Leider gelingt es mir nicht diesen Index zu erstellen.
    Bei der Erstellung eines Index kommt Fehler 1939 (Could not create index because the view is not schema bound.

    Dann dachte ich miir, dass ich mit ALTER VIEW WITH SCHEMABINDING etwas bewirken könnte. Das läßt sich allerdings nicht ausführen.
    Fehler:

    Msg 4512, Level 16, State 3, Procedure VIEW_Hauptabelle
    , Line 5 Cannot schema bind view 'dbo.VIEW_Hauptabelle
    because name 'basis.dbo.Profiles' is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.

    Ich verstehe hier das Problem nicht so ganz. Die Tabelle Profiles ist mehrfach mit der Hauptabelle verbunden und jeweils über zwei Felder verknüpft. Ist das, das Problem?

    Wäre toll, wenn mir jemand das Problem erklären könnte.

    Gruß Stefan
    Application Management
    Microsoft Dynamics NAV - Microsoft Dynamics CRM - Microsoft Access - SQL Server

  • #2
    Originally posted by dancer1970 View Post
    Msg 4512, Level 16, State 3, Procedure VIEW_Hauptabelle
    , Line 5 Cannot schema bind view 'dbo.VIEW_Hauptabelle
    because name 'basis.dbo.Profiles' is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.
    Anscheinend mag er den Datenbanknamen in 'basis.dbo.Profiles' nicht...

    Comment


    • #3
      Ich glaube es liegt daran, dass deine View sich nicht nur auf eine Datenbank bezieht Das geht nicht.

      Comment


      • #4
        Hallo,
        am Dantenbanknamen liegt es nicht.
        Es stimmt, dass sich die View auf mehrere Datenbanken in der gleichen Instanz bezieht.
        Das ist aber sehr schade, dass das nicht funktioniert. Dieses Problem wird mich dann öfter treffen, weil nämlich bei uns die Bewegungsdaten und Stammdaten grundsätzlich in unterschiedlichen Datenbanken befinden.

        Gibt es eine Lösung?
        Application Management
        Microsoft Dynamics NAV - Microsoft Dynamics CRM - Microsoft Access - SQL Server

        Comment


        • #5
          Hallo dancer1970,

          wie sieht denn dein Befehl zur View- und IndexErstellung aus?
          Hab dies eben erfolgreich mit dem MS SQL Server 2008 getestet.
          http://www.java2s.com/Tutorial/SQLSe...exingaView.htm

          Es soll wichtig sein, dass der Index "UNIQUE CLUSTERED INDEX" ist.
          knoxyz
          Und Falk Prüfer sprach: Formatierung von SQL in Beiträgen

          Comment


          • #6
            Hallo,
            das Script für den Index sieht wie folgt aus:

            Code:
            USE [DW]
            GO
            SET ARITHABORT ON
            GO
            SET CONCAT_NULL_YIELDS_NULL ON
            GO
            SET QUOTED_IDENTIFIER ON
            GO
            SET ANSI_NULLS ON
            GO
            SET ANSI_PADDING ON
            GO
            SET ANSI_WARNINGS ON
            GO
            SET NUMERIC_ROUNDABORT OFF
            GO
            CREATE UNIQUE CLUSTERED INDEX [IX_orderno] ON [dbo].[VIEW_Auswertung_2] 
            (
            	[Order_No_] ASC
            )WITH (STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
            GO
            Die Erstellung wird mit dem Fehler abgebrochen:
            Msg 1939, Level 16, State 1, Line 1
            Cannot create index on view 'VIEW_Auswertung_2' because the view is not schema bound.

            Ein Schemabinding bekomme ich aber nicht hin:
            Code:
            SET ANSI_NULLS ON
            GO
            
            SET QUOTED_IDENTIFIER ON
            GO
            
            
            CREATE VIEW [dbo].[VIEW_CCRC_Auswertung_3] WITH SCHEMABINDING
            AS
            SELECT  ....
            Siehe Fehler im Beitrag 1 (Msg 4512, Level 16, State 3)
            Application Management
            Microsoft Dynamics NAV - Microsoft Dynamics CRM - Microsoft Access - SQL Server

            Comment


            • #7
              Nochmals zum Schemabinding:
              Schemabinding geht nur, wenn die View NUR auf Tabellen innerhalb derselben Datenbank zugreift. Daher sind auch keine dreiteiligenNamen wie 'basis.dbo.Profiles' innerhalb der View erlaubt. Man darf also keinen Datenbanknamen, muss aber den Schemanamen immer mit angeben, also etwa so:

              create dbo.meineView with SCHEMABINDING as
              select feld1, feld2, ... from dbo.meineTabelle

              Erfüllt das deine View?


              bye,
              Helmut

              PS: ich glaube, es kann auch Probleme geben, wenn man Aliasnamen oder selbst definierte Datentypen verwendet (habe ich aber noch nicht ausprobiert).

              Comment

              Working...
              X