Per quetsioni di tempo ho creato io una mia soluzione, la posto qui per il futuro.
Non ho potuto visitare i link che mi hai proposto ma ci farò un giro al più presto.
Grazie
ciao
codice:
declare @constname sysname,
@cmd varchar(1024)
--------------------------
declare @result nvarchar(4000)
set @result=''
declare @allTable sysname
declare curs_tableName cursor for
select name
from sysobjects
where xtype in ('U')
order by name
open curs_tableName
fetch next from curs_tableName into @allTable
while (@@fetch_status = 0)
begin
--set @result=@result+'-'+@allTable
--------------------------
declare curs_constraints cursor for
select name
from sysobjects --F=foreign pk=primary
where xtype in ('C', 'F', 'UQ', 'D')
and (status & 64) = 0
and parent_obj = object_id('gat_i.gat_i.'+@allTable)--@tablename)
open curs_constraints
fetch next from curs_constraints into @constname
while (@@fetch_status = 0)
begin
exec('alter table gat_i.gat_i.'+@allTable+' nocheck constraint all')
--select @cmd = 'ALTER TABLE ' + @tablename + ' DROP CONSTRAINT ' + @constname
select @cmd = 'ALTER TABLE gat_i.gat_i.'+ @allTable + ' DROP CONSTRAINT ' + @constname
set @result=@result+ '^P'+@cmd
exec(@cmd)
exec('alter table gat_i.gat_i.'+@allTable+' check constraint all')
fetch next from curs_constraints into @constname
end
close curs_constraints
deallocate curs_constraints
---------
fetch next from curs_tableName into @allTable
end
close curs_tableName
deallocate curs_tableName
----
select 'Tutti i constraint eliminati tranne le primary key'
-----------------eliminiamo le primary key
declare curs_tableName cursor for
select name
from sysobjects
where xtype in ('U')
order by name
open curs_tableName
fetch next from curs_tableName into @allTable
while (@@fetch_status = 0)
begin
--set @result=@result+'-'+@allTable
--------------------------
declare curs_constraints cursor for
select name
from sysobjects --F=foreign pk=primary
where xtype in ('C', 'F', 'PK', 'UQ', 'D')
and (status & 64) = 0
and parent_obj = object_id('gat_i.gat_i.'+@allTable)--@tablename)
open curs_constraints
fetch next from curs_constraints into @constname
while (@@fetch_status = 0)
begin
exec('alter table gat_i.gat_i.'+@allTable+' nocheck constraint all')
--select @cmd = 'ALTER TABLE ' + @tablename + ' DROP CONSTRAINT ' + @constname
select @cmd = 'ALTER TABLE gat_i.gat_i.'+@allTable + ' DROP CONSTRAINT ' + @constname
set @result=@result+ '^P'+@cmd
exec(@cmd)
exec('alter table gat_i.gat_i.'+@allTable+' check constraint all')
fetch next from curs_constraints into @constname
end
close curs_constraints
deallocate curs_constraints
----
fetch next from curs_tableName into @allTable
end
close curs_tableName
deallocate curs_tableName
----
select 'primary key eliminate'