|
|
|
Невозможно удалить поле.
|
|||
|---|---|---|---|
|
#18+
После проверки на сущестование определенного столбца ТИПА if exists(select * from information_schema.columns where table_name=@Alias and column_name=@Field) ....... невозможно удалить указанный столбец.... Выдается сообщение типа The object 'DF__HOUSES__fld_m__04459E07' is dependent on column '....' Можно ли закрыть объект созданный selectом ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.08.2002, 13:46:32 |
|
||
|
Невозможно удалить поле.
|
|||
|---|---|---|---|
|
#18+
прежде чем удалить столбец - нужно удалять все ограничения целостности, связанные с ним, в том числе и значения по умолчанию ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.08.2002, 14:38:05 |
|
||
|
Невозможно удалить поле.
|
|||
|---|---|---|---|
|
#18+
Для определения задействованности столбца в каких_либо ограничениях я исп. нижеприведенній фрагмент ЫЗ set nocount on declare @T sysname select @T='users.isp' -- Анализ.столбец -- ............................................................................ -- Формирование операторов удаления первичного ключа и -- ссылающихся на него всех внешних ключей, значений по -- умолчанию и ограничений на значение, касающихся указанного -- столбца таблицы - @T = 'имя_таблицы.имя_столбца' -- ............................................................................ declare @NAM_C sysname, @NAM_T sysname, @CCC sysname, @TTT sysname, @IDT int, @I int, @IDC int, @R int, @L int, @COL_PREC int, @COL_SCAL int, @COL_NULL tinyint, @FFF varchar(2000), @OT tinyint declare @StrucDB table (i int NOT NULL identity, t varchar(255) collate database_default NULL) select @L=charindex('.',@T), @NAM_C=substring(@T,@L+1,datalength(@T)-@L), @NAM_T=substring(@T,1,@L-1), @IDT=object_id(@NAM_T), @NAM_T=object_name(@IDT) if not exists(select '*' from sysobjects where xtype = 'U' and status >= 0 and OBJECTPROPERTY(id,N'IsUserTable') = 1 and name = @NAM_T) begin raiserror ('The table - is unknown!',13,3) return end if not exists(select '*' from sysobjects o, syscolumns c where c.id = o.id and o.xtype = 'U' and o.name = @NAM_T and c.name = @NAM_C and o.status >= 0) begin raiserror ('The column - is unknown!',13,3) return end -- DFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDF declare cur_Sel_Def_Col cursor local for select id, name from sysobjects where parent_obj = @IDT and xtype = 'D' open cur_Sel_Def_Col fetch next from cur_Sel_Def_Col into @R,@CCC while @@FETCH_STATUS >= 0 begin select @TTT=name from syscolumns where id = @IDT and cdefault = @R if @TTT = @NAM_C begin insert into @StrucDB values ('alter table '+@NAM_T+' drop constraint '+@CCC) break end fetch next from cur_Sel_Def_Col into @R,@CCC end close cur_Sel_Def_Col deallocate cur_Sel_Def_Col -- CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC declare cur_Sel_Cc_Col cursor local for select id, name from sysobjects where parent_obj = @IDT and xtype = 'C' open cur_Sel_Cc_Col fetch next from cur_Sel_Cc_Col into @R,@CCC while @@FETCH_STATUS >= 0 begin if exists(select '*' from syscomments where id = @R and colid = 1 and charindex('['+@NAM_C+']',text) !=0) begin insert into @StrucDB values ('alter table '+@NAM_T+' drop constraint '+@CCC) break end fetch next from cur_Sel_Cc_Col into @R,@CCC end close cur_Sel_Cc_Col deallocate cur_Sel_Cc_Col -- PKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPK select @L=0,@I=1,@TTT='?' select @R=indid,@CCC=name from sysindexes where id = @IDT and indid > 0 and indid < 255 and (status & 64)=0 and (status&2048) != 0 while (@TTT is not null ) begin select @TTT = index_col(@NAM_T,@R,@I),@I=@I+1 if @TTT = @NAM_C begin select @L=1 break end end if @L != 0 begin -- FKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFK declare cur_DrpDepTab_FK cursor local for select a.constid,b.parent_obj from sysreferences a,sysobjects b where a.rkeyid = @IDT and a.constid = b.id and b.xtype = 'F' open cur_DrpDepTab_FK fetch next from cur_DrpDepTab_FK into @R,@I while @@FETCH_STATUS >= 0 begin insert into @StrucDB values ('alter table '+object_name(@I)+ ' drop constraint '+object_name(@R)) fetch next from cur_DrpDepTab_FK into @R,@I end close cur_DrpDepTab_FK deallocate cur_DrpDepTab_FK insert into @StrucDB values ('alter table '+@NAM_T+' drop constraint '+@CCC) end if (select count(*) from @StrucDB) != 0 insert into @StrucDB values ('go') select t from @StrucDB order by i -- if (select count(*) from @StrucDB) = 0 return 3 return 0 end -- ============================================================================ -- return 0 go -- РЕЗУЛЬТАТ alter table SALDO drop constraint FK_SALDO__USERS alter table OPER drop constraint FK_OPER__USERS alter table OPER_ARX drop constraint FK_OPER_ARX__USERS alter table OPER_Y drop constraint FK_OPER_Y__USERS alter table SIGN_DOC drop constraint FK_SIGN_DOC__USERS alter table GRU_USERS drop constraint FK_GRU_USERS__USERS alter table SH_ACCOUNT drop constraint FK_SH_ACCOUNT__USERS alter table NP drop constraint FK_NP__USERS alter table SIGN_REE_DOC drop constraint FK_SIGN_REE_DOC__USERS alter table ARM_USERS drop constraint FK_ARM_USERS__USERS alter table USERS drop constraint PK_USERS go ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.08.2002, 15:13:43 |
|
||
|
Невозможно удалить поле.
|
|||
|---|---|---|---|
|
#18+
Для определения задействованности столбца в каких_либо ограничениях я исп. нижеприведенній фрагмент ЫЗ set nocount on declare @T sysname select @T='users.isp' -- Анализ.столбец -- ............................................................................ -- Формирование операторов удаления первичного ключа и -- ссылающихся на него всех внешних ключей, значений по -- умолчанию и ограничений на значение, касающихся указанного -- столбца таблицы - @T = 'имя_таблицы.имя_столбца' -- ............................................................................ declare @NAM_C sysname, @NAM_T sysname, @CCC sysname, @TTT sysname, @IDT int, @I int, @IDC int, @R int, @L int, @COL_PREC int, @COL_SCAL int, @COL_NULL tinyint, @FFF varchar(2000), @OT tinyint declare @StrucDB table (i int NOT NULL identity, t varchar(255) collate database_default NULL) select @L=charindex('.',@T), @NAM_C=substring(@T,@L+1,datalength(@T)-@L), @NAM_T=substring(@T,1,@L-1), @IDT=object_id(@NAM_T), @NAM_T=object_name(@IDT) if not exists(select '*' from sysobjects where xtype = 'U' and status >= 0 and OBJECTPROPERTY(id,N'IsUserTable') = 1 and name = @NAM_T) begin raiserror ('The table - is unknown!',13,3) return end if not exists(select '*' from sysobjects o, syscolumns c where c.id = o.id and o.xtype = 'U' and o.name = @NAM_T and c.name = @NAM_C and o.status >= 0) begin raiserror ('The column - is unknown!',13,3) return end -- DFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDF declare cur_Sel_Def_Col cursor local for select id, name from sysobjects where parent_obj = @IDT and xtype = 'D' open cur_Sel_Def_Col fetch next from cur_Sel_Def_Col into @R,@CCC while @@FETCH_STATUS >= 0 begin select @TTT=name from syscolumns where id = @IDT and cdefault = @R if @TTT = @NAM_C begin insert into @StrucDB values ('alter table '+@NAM_T+' drop constraint '+@CCC) break end fetch next from cur_Sel_Def_Col into @R,@CCC end close cur_Sel_Def_Col deallocate cur_Sel_Def_Col -- CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC declare cur_Sel_Cc_Col cursor local for select id, name from sysobjects where parent_obj = @IDT and xtype = 'C' open cur_Sel_Cc_Col fetch next from cur_Sel_Cc_Col into @R,@CCC while @@FETCH_STATUS >= 0 begin if exists(select '*' from syscomments where id = @R and colid = 1 and charindex('['+@NAM_C+']',text) !=0) begin insert into @StrucDB values ('alter table '+@NAM_T+' drop constraint '+@CCC) break end fetch next from cur_Sel_Cc_Col into @R,@CCC end close cur_Sel_Cc_Col deallocate cur_Sel_Cc_Col -- PKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPKPK select @L=0,@I=1,@TTT='?' select @R=indid,@CCC=name from sysindexes where id = @IDT and indid > 0 and indid < 255 and (status & 64)=0 and (status&2048) != 0 while (@TTT is not null ) begin select @TTT = index_col(@NAM_T,@R,@I),@I=@I+1 if @TTT = @NAM_C begin select @L=1 break end end if @L != 0 begin -- FKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFK declare cur_DrpDepTab_FK cursor local for select a.constid,b.parent_obj from sysreferences a,sysobjects b where a.rkeyid = @IDT and a.constid = b.id and b.xtype = 'F' open cur_DrpDepTab_FK fetch next from cur_DrpDepTab_FK into @R,@I while @@FETCH_STATUS >= 0 begin insert into @StrucDB values ('alter table '+object_name(@I)+ ' drop constraint '+object_name(@R)) fetch next from cur_DrpDepTab_FK into @R,@I end close cur_DrpDepTab_FK deallocate cur_DrpDepTab_FK insert into @StrucDB values ('alter table '+@NAM_T+' drop constraint '+@CCC) end if (select count(*) from @StrucDB) != 0 insert into @StrucDB values ('go') select t from @StrucDB order by i -- if (select count(*) from @StrucDB) = 0 return 3 return 0 end -- ============================================================================ -- return 0 go -- РЕЗУЛЬТАТ alter table SALDO drop constraint FK_SALDO__USERS alter table OPER drop constraint FK_OPER__USERS alter table OPER_ARX drop constraint FK_OPER_ARX__USERS alter table OPER_Y drop constraint FK_OPER_Y__USERS alter table SIGN_DOC drop constraint FK_SIGN_DOC__USERS alter table GRU_USERS drop constraint FK_GRU_USERS__USERS alter table SH_ACCOUNT drop constraint FK_SH_ACCOUNT__USERS alter table NP drop constraint FK_NP__USERS alter table SIGN_REE_DOC drop constraint FK_SIGN_REE_DOC__USERS alter table ARM_USERS drop constraint FK_ARM_USERS__USERS alter table USERS drop constraint PK_USERS go ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.08.2002, 15:13:51 |
|
||
|
Невозможно удалить поле.
|
|||
|---|---|---|---|
|
#18+
Спасибо всем, а то бы ковырялся еще... спасибо....!!! ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 07.08.2002, 06:31:35 |
|
||
|
Невозможно удалить поле.
|
|||
|---|---|---|---|
|
#18+
ХМ. Дело в том, чо ХП получает имя таблицы и поля.. имя ограничения не известно... и как интересно я его удалять буду? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 07.08.2002, 06:59:38 |
|
||
|
Невозможно удалить поле.
|
|||
|---|---|---|---|
|
#18+
И от седа вытекает вопрос как можно узнать имя ограничения на столбец и возможно значение ограничения? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 07.08.2002, 07:03:12 |
|
||
|
|

start [/forum/topic.php?fid=46&msg=32041445&tid=1821318]: |
0ms |
get settings: |
6ms |
get forum list: |
13ms |
check forum access: |
2ms |
check topic access: |
2ms |
track hit: |
45ms |
get topic data: |
9ms |
get forum data: |
2ms |
get page messages: |
45ms |
get tp. blocked users: |
1ms |
| others: | 197ms |
| total: | 322ms |

| 0 / 0 |
