日期:2014-05-19  浏览次数:20413 次

同步后删除rowguid列的问题
大家好:
数据库同步后,   有同步的表新增rowguid列,   备份恢复在测试数据时想把所有的rowguid删除!

我用这样的sql:  

use   W1_Au_Test
go
declare   @tbname   varchar(250)    
declare   #tb   cursor  
for     select       name       from       sysobjects   where   xtype= 'u '   and   id   in   (select   id   from   syscolumns   where   name= 'rowguid ')
open   #tb    
fetch   next   from   #tb   into   @tbname  
while   @@fetch_status=0    
begin
exec( 'alter   table   [ '+@tbname+ ']   disable   trigger   all ')  
exec( 'alter   table   [ '+@tbname+ ']   drop   column   RowGuid ')  
exec( 'alter   table   [ '+@tbname+ ']   enable   trigger   all ')  
  fetch   next   from   #tb   into   @tbname    
end
close   #tb
deallocate   #tb  

在查询分析器中执行时,   提示:

Server:   Msg   5074,   Level   16,   State   1,   Line   1
The   object   'DF_PURCHASE_ITEM_rowguid '   is   dependent   on   column   'RowGuid '.
Server:   Msg   5074,   Level   16,   State   1,   Line   1
The   index   'index_4247120 '   is   dependent   on   column   'RowGuid '.
Server:   Msg   4922,   Level   16,   State   1,   Line   1
ALTER   TABLE   DROP   COLUMN   RowGuid   failed   because   one   or   more   objects   access   this   column.

请问怎么解决呢?
谢谢各位!


------解决方案--------------------
帮你顶吧
------解决方案--------------------
sql server 不应该在这里问吧。
------解决方案--------------------
先删除该RowGuid的Default约束和相关的索引
------解决方案--------------------

删除列RowGuid之前,先要删除该列上的相关约束和索引
exec( 'alter table [ '+@tbname+ '] drop column RowGuid ')