dobear
Nerver try, nerver know
登录
注册
全站
当前博客
空间
博客
好友
相册
论坛
留言
用户操作
[即时聊天]
[发私信]
[加为好友]
dobear
ID:dobear_0922
共
8094
次访问,排名
13505(-7)
,好友
82
人,关注者
158
人。
dobear
dobear_0922的文章
原创 14 篇
翻译 0 篇
转载 3 篇
评论 26 篇
最近评论
救援隊募集:
アダルト
エロ
不倫
guoyz_1:
顶你
guoyz_1:
顶你
guoyz_1:
顶你
guoyz_1:
顶你
文章分类
SQL
(RSS)
收藏
相册
bear
SQL
Leo——感谢生活!
(RSS)
天道酬勤
(RSS)
石头
(RSS)
近身剪
(RSS)
存档
2008年11月(2)
2008年06月(4)
2008年05月(2)
2008年04月(4)
2008年03月(1)
2007年12月(2)
2007年11月(1)
2007年10月(1)
软件项目交易
订阅我的博客
禁用聚集索引来阻止对表的访问(暂停使用某个表,但不删除)
收藏
新一篇: 转-80后男士征婚标准(巨经典)
|
旧一篇: 测试索引对数据物理存储顺序的影响
--
=============================================
--
标题:禁用聚集索引来阻止对表的访问(暂停使用某个表,但不删除)
--
作者:dobear
--
环境:SQL2005
--
日期:2008-04-01
--
=============================================
use
Testdb
--
选择数据库,请使用服务器上已有的数据库
if
object_id
(N
'
tb
'
,
'
U
'
)
is
not
null
drop
table
tb
go
--
1 创建测试表,添加测试数据
create
table
tb
(
id
int
primary
key
,
name
nvarchar
(
32
)
)
insert
tb
select
1
,
'
1111
'
insert
tb
select
3
,
'
3333
'
insert
tb
select
2
,
'
2222
'
--
禁用前
select
*
from
tb
--
正常,能查到数据
/**/
/*
id name
----------- --------------------------------
1 1111
2 2222
3 3333
(3 row(s) affected)
*/
--
找到聚集索引(一般主键上会默认创建一个聚集索引),然后禁用
declare
@sql
nvarchar
(
max
),
@index
sysname
select
@index
=
name
from
sys.indexes
where
object_id
=
object_id
(N
'
tb
'
)
and
type
=
1
set
@sql
=
'
alter index
'
+
@index
+
'
on tb Disable
'
exec
(
@sql
)
--
禁用后
select
*
from
tb
--
报错,表不可用
/**/
/*
Msg 8655, Level 16, State 1, Line 22
The query processor is unable to produce a plan because the index 'PK__tb__1BC821DD' on table or view 'tb' is disabled.
*/
发表于 @
2008年04月01日 11:19:00
|
评论(
loading...
)
|
编辑
新一篇: 转-80后男士征婚标准(巨经典)
|
旧一篇: 测试索引对数据物理存储顺序的影响
评论
#
suxiaojack 发表于2008-04-01 14:51:45 IP: 220.207.207.*
晕!我还不如直接改了表的名字来得更快!
2008-04-02 13:40:04作者回复
呵呵,你改了表名,表中的内容还是可以访问
发表评论
姓 名:
主 页:
校验码:
看不清,换一张
登录