我创建索引的语句如下
create nonclustered index IX_transInfo_cardID
on transInfo(cardID)
with fillfactor=70
select * from transInfo (INDEX=IX_transInfo_cardID) where cardID='1010 3576 1212 1134'
cardID是transInfo表的外键
遇到的问题如下
Msg 1018, Level 15, State 1, Line 7
Incorrect syntax near 'INDEX'. If this is intended as a part of a table hint, A WITH keyword and parenthesis are now required. See SQL Server Books Online for proper syntax.

解决方案 »

  1.   

    select * from transInfo with (INDEX=IX_transInfo_cardID) where cardID='1010 3576 1212 1134' 
      

  2.   

    select * from transInfo with (INDEX=IX_transInfo_cardID) where cardID='1010 3576 1212 1134' 
      

  3.   


    select * from transInfo with (INDEX=IX_transInfo_cardID) where cardID='1010 3576 1212 1134' 
      

  4.   

    用了这句后又有这样的错误
    Msg 308, Level 16, State 1, Line 7
    Index 'IX_transInfo_cardID' on table 'transInfo' (specified in the FROM clause) does not exist.
      

  5.   

    第一句运行一次就行了create nonclustered index IX_transInfo_cardID
    on transInfo(cardID)
    with fillfactor=70goselect * from transInfo with(INDEX=IX_transInfo_cardID) where cardID='1010 3576 1212 1134' 
      

  6.   

    分批执行的情况下,第二句就可以预编译成功了,否则没有IX_transInfo_cardID 的情况下第二句会抱错。