存储过程如下:
CREATE procedure proc_get_list
@type_code varchar(10) --类型代码as
set nocount onselect prodcut.name,product.pic from product where prodcut.type_code like @type_code+'%' GO执行 procedure proc_get_list '2001' 需要11秒如果换成下面的
CREATE procedure proc_get_list2
@type_code varchar(10) --类型代码as
set nocount ondeclare @type_code2 varchar(10)
set @type_code2=@type_codeselect prodcut.name,product.pic from product where prodcut.type_code like @type_code2+'%' GO
执行procedure proc_get_list2 '2001' 需要0秒把SQL单独复制出来
declare @type_code2 varchar(10)
set @type_code2='2001'select prodcut.name,product.pic from product where prodcut.type_code like @type_code2+'%' 执行需要0秒,请问为什么第一种的速度这么慢.
已经在表prodcut的type_code上建立了非聚焦索引,尝度过去掉索引,换成聚焦索引,速度没有变化.
CREATE procedure proc_get_list
@type_code varchar(10) --类型代码as
set nocount onselect prodcut.name,product.pic from product where prodcut.type_code like @type_code+'%' GO执行 procedure proc_get_list '2001' 需要11秒如果换成下面的
CREATE procedure proc_get_list2
@type_code varchar(10) --类型代码as
set nocount ondeclare @type_code2 varchar(10)
set @type_code2=@type_codeselect prodcut.name,product.pic from product where prodcut.type_code like @type_code2+'%' GO
执行procedure proc_get_list2 '2001' 需要0秒把SQL单独复制出来
declare @type_code2 varchar(10)
set @type_code2='2001'select prodcut.name,product.pic from product where prodcut.type_code like @type_code2+'%' 执行需要0秒,请问为什么第一种的速度这么慢.
已经在表prodcut的type_code上建立了非聚焦索引,尝度过去掉索引,换成聚焦索引,速度没有变化.
解决方案 »
- 统计在线时间问题
- SQL Server 不存在或访问被拒绝
- 字符串转义问题?XP_CMDSHELL的参数问题
- 用合名管道连接sql服务器时,登录用户必须要有服务器上ipc$的访问权限,这句话是什么意思呀?查了好长时间,就是没找到答案
- Sql Server 变态问题求救(删除数据库同名用户的问题)[给分帖,zjcxc(邹建) 请进][内有未解决问题,如有人能解惑另外开贴给分]
- 部分字段重复的查询语句
- 企业管理器的奇怪错误!
- 高手帮忙,我想景象自动统计
- 急急急,请问 sql 2005 中文日期时间格式字符串转为日期时间怎么办
- sql server 视图建立的原理
- SQL中的NF
- SQL2005 Reporting Services 报表动态生成列?
RECOMPILE
指示数据库引擎不缓存该过程的计划,该过程在运行时编译。如果指定了 FOR REPLICATION,则不能使用此选项。对于 CLR 存储过程,不能指定 RECOMPILE。若要指示数据库引擎放弃存储过程内单个查询的计划,请使用 RECOMPILE 查询提示。有关详细信息,请参阅查询提示 (Transact-SQL)。如果非典型值或临时值仅用于属于存储过程的查询子集,则使用 RECOMPILE 查询提示。