use pubs
create unique clustered index ix_authors_view
on dbo.authors_view ([author])
on [primary]
go
 
服务器: 消息 1939,级别 16,状态 1,行 2
无法在视图 'authors_VIEW' 上创建 索引,因为该视图未绑定到架构。

解决方案 »

  1.   

    索引视图受限于以下的附加限制:     
        
      索引的创建者必须拥有表。所有表、视图和索引必须在同一数据库中创建。   
        
        
      定义索引视图的   SELECT   语句不得包含视图、行集函数、行内函数或派生表。同一物理表在该语句中只能出现一次。   
        
        
      在任何联接表中,均不允许进行   OUTER   JOIN   操作。   
        
        
      搜索条件中不允许使用子查询或者   CONTAINS   或   FREETEXT   谓词。   
        
        
      如果视图定义包含   GROUP   BY   子句,则视图的   SELECT   列表中必须包含所有分组依据列及   COUNT_BIG(*)   表达式。此外,CREATE   UNIQUE   CLUSTERED   INDEX   子句中必须只包含这些列。
      

  2.   

    你编辑一下视图 'authors_VIEW' 
    ALTER VIEW authors_VIEW
    WITH SCHEMABINDING -- 加上这个绑定架构
    AS
    ......然后就可以建立索引了
      

  3.   

    ALTER VIEW authors_VIEW
    WITH SCHEMABINDING -- 加上这个绑定架构
    AS
    select dbo.authors.au_lname,dbo.authors.au_fname,
    dbo.titles.title,dbo.sales.qty,dbo.sales.ord_date
    from dbo.authors,dbo.titleauthor,titles,sales
    where dbo.authors.au_id=dbo.titleauthor.au_id
    and dbo.titleauthor.title_id=
    dbo.titles.title_id and 
    dbo.titles.title_id=dbo.sales.title_id服务器: 消息 4512,级别 16,状态 3,过程 authors_VIEW,行 4
    无法将 视图 'authors_VIEW' 绑定到架构,因为名称 'titles' 对于架构绑定无效。名称必须由两部分构成,并且对象不能引用自身。
      

  4.   

    from dbo.authors,dbo.titleauthor,titles,sales 这里错了,你仔细检查一下
      

  5.   

    ALTER VIEW authors_VIEW
    WITH SCHEMABINDING -- 加上这个绑定架构
    AS
    select dbo.authors.au_lname,dbo.authors.au_fname,
    dbo.titles.title,dbo.sales.qty,dbo.sales.ord_date
    from dbo.authors inner join
    dbo.titleauthor on dbo.authors.au_id=
    dbo.titleauthor.au_id inner join
    dbo.titles on 
    dbo.titleauthor.title_id=dbo.titles.title_id
    inner join
    dbo.sales on
    dbo.titles.title_id=dbo.sales.title_id
    楼上正解
      

  6.   

    WITH SCHEMABINDING 创建视图,选择表须有两步份组成
    即schema.tablename
    而且不能使用*,即select * from schema.tablename是无效的,需要写出具体的列名