创建索引时遇到的问题

adventurous 2009-08-27 01:55:49
我创建索引的语句如下
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.
...全文
154 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinjazz 2009-08-27
  • 打赏
  • 举报
回复
分批执行的情况下,第二句就可以预编译成功了,否则没有IX_transInfo_cardID 的情况下第二句会抱错。
--小F-- 2009-08-27
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 adventurous 的回复:]
引用 6 楼 jinjazz 的回复:
第一句运行一次就行了

create nonclustered index IX_transInfo_cardID
on transInfo(cardID)
with fillfactor=70

go

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

这次就好了,但为什么加个go就行了
[/Quote]

GO是表示执行语句结果
adventurous 2009-08-27
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 jinjazz 的回复:]
第一句运行一次就行了

create nonclustered index IX_transInfo_cardID
on transInfo(cardID)
with fillfactor=70

go

select * from transInfo with(INDEX=IX_transInfo_cardID) where cardID='1010 3576 1212 1134'
[/Quote]
这次就好了,但为什么加个go就行了
jinjazz 2009-08-27
  • 打赏
  • 举报
回复
第一句运行一次就行了

create nonclustered index IX_transInfo_cardID
on transInfo(cardID)
with fillfactor=70

go

select * from transInfo with(INDEX=IX_transInfo_cardID) where cardID='1010 3576 1212 1134'
adventurous 2009-08-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 yang_ 的回复:]
SQL codeselect*from transInfowith (INDEX=IX_transInfo_cardID)where cardID='1010 3576 1212 1134'
[/Quote]
用了这句后又有这样的错误
Msg 308, Level 16, State 1, Line 7
Index 'IX_transInfo_cardID' on table 'transInfo' (specified in the FROM clause) does not exist.
lihan6415151528 2009-08-27
  • 打赏
  • 举报
回复

select * from transInfo with (INDEX=IX_transInfo_cardID) where cardID='1010 3576 1212 1134'
jinjazz 2009-08-27
  • 打赏
  • 举报
回复
select * from transInfo with (INDEX=IX_transInfo_cardID) where cardID='1010 3576 1212 1134'
Yang_ 2009-08-27
  • 打赏
  • 举报
回复
select * from transInfo with (INDEX=IX_transInfo_cardID) where cardID='1010 3576 1212 1134' 
zc_0101 2009-08-27
  • 打赏
  • 举报
回复
帮顶

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧