baiynije 发表于 2013-01-29 16:25

請教一個問題,修改表名後一定要重建存儲過程嗎?
用sp_recompile重新編譯一下可不可以?

2BeSybPro 发表于 2013-01-29 22:35

baiynije 发表于 2013-01-29 16:25 static/image/common/back.gif
請教一個問題,修改表名後一定要重建存儲過程嗎?
用sp_recompile重新編譯一下可不可以?

Procedures and triggers that depend on an object whose name has been changed work until they are dropped and re-created.


1> create table test(id int, name varchar(20))
2> go
1> insert into test values(1,'baiynije')
2> go
(1 row affected)
1> select * from test
2> go
id          name
----------- --------------------
         1 baiynije

(1 row affected)
1> create procedure test_proc
2> as
3> select * from test
4> go
1> exec test_proc
2> go
id          name
----------- --------------------
         1 baiynije

(1 row affected)
(return status = 0)
1> sp_rename test,test_tbl
2> go
Object name has been changed.
Warning: Changing an object or column name could break existing stored procedures, cached statements or other compiled objects.
(return status = 0)
1> sp_recompile test_tbl
2> go
Each stored procedure and trigger that uses table 'test_tbl' will be recompiled the next time it is executed.
(return status = 0)
1> exec test_proc
2> go
Msg 208, Level 16, State 1:
Server 'xxxxx', Procedure 'test_proc', Line 3:
test not found. Specify owner.objectname o

baiynije 发表于 2013-01-30 16:37

2BeSybPro 发表于 2013-01-29 22:35 static/image/common/back.gif
Procedures and triggers that depend on an object whose name has been changed work until they are ...
謝謝,可能是我沒說清楚,
我的意思是假如有個表test1 ,該表出現問題,我想建一個新表來替代它
如select * into test2 from test1 where ...
然後將原test1 改為其它名字,test1_old
再將test2 改為test1,此時使用到test1的存儲過程應該不用刪除重新建立吧?

2BeSybPro 发表于 2013-01-30 22:46

baiynije 发表于 2013-01-30 16:37 static/image/common/back.gif
謝謝,可能是我沒說清楚,
我的意思是假如有個表test1 ,該表出現問題,我想建一個新表來替代它
如selec ...

是的,直接用sp_recompile就行,可以不用删除重建procedures/triggers。以前v12.5 sp_recompile不能解决跨库引用表名变更,v15可以了。

baiynije 发表于 2013-01-31 08:55

2BeSybPro 发表于 2013-01-30 22:46 static/image/common/back.gif
是的,直接用sp_recompile就行,可以不用删除重建procedures/triggers。以前v12.5 sp_recompile不能解决 ...
謝謝,還想請教一個關於reorg rebuild 的問題,
就是在平時的維護中需要定時去用reorg rebuild重建表嗎,之前做時出現一個問題,就是當某個表有問題時,執行reorg rebuild 後有問題的數據就直接刪除了,以至後來不敢隨便使用了,rebuild之前是不是要用dbcc 檢查一下數據庫?另外有些表比較大,有幾千萬條的數據,這種表要如何去維護?目前我是只rebuild 索引或只更新索引統計信息,還請指教。

2BeSybPro 发表于 2013-01-31 23:56

baiynije 发表于 2013-01-31 08:55 static/image/common/back.gif
謝謝,還想請教一個關於reorg rebuild 的問題,
就是在平時的維護中需要定時去用reorg rebuild重建表嗎, ...

Reorg rebuild table以前有个版本(记得是v12.0)会掉数据,这个bug已经被修复了。注意reorg rebuild table会放exclusive table lock(v15.7有所改进,做到了部分online reorg),如果是业务关键表会导致系统不可用;而且reorg rebuild table要求打开"select into" option和有足够大的free space (same size as the table and its indexes)。因为fragmentation主要在index上,用reorg rebuild index/update statistics 就好了,reorg index holds ex_intent lock, 不会导致severe blocking。

这方面的日常维护:
1. weekly dbcc checks
2. weekly reorg rebuild index (you can include reorg compact if necessary)
3. daily update statistics

如果你的系统不是24x7,可以在周末做reorg rebuild table;否则的话,就只有找个window做年度reorg table.

baiynije 发表于 2013-02-01 13:52

2BeSybPro 发表于 2013-01-31 23:56 static/image/common/back.gif
Reorg rebuild table以前有个版本(记得是v12.0)会掉数据,这个bug已经被修复了。注意reorg rebuild tab ...

非常感谢!
我们的系统是7*24的,只能找一些全体放假的时候才能做rebuild了,还有因为数据库空间有限,一些大的表很难去做rebuild,希望sybase 在这方面有所改进。
页: 1 [2]
查看完整版本: Sybase中大的update一定要用小批量(small batch size) - 附例子