Disabling Constraint for Bulk Loading



Greetings,
I want to bulk load data into user defined SQL Server
tables. For this i want to disable all the constraints on all the user
defined tables.
I got solution in one of the thread and did the following:

declare @tablename varchar(30)
declare c1 cursor for select name from sysobjects where type = 'U'
open c1
fetch next from c1 into @tablename
while ( @@fetch_status <> -1 )
begin
exec ( 'alter table ' + @tablename + ' check constraint all ')
fetch next from c1 into @tablename
end
deallocate c1
go

Now when i try to truncate one of the tables (say titles) it gives me
the following error:

Cannot truncate table 'titles' because it is being referenced by a
FOREIGN KEY constraint.

Can anyone show me the right path? I am working on ASE 12.5

TIA

.



Relevant Pages

  • Re: truncate tables in my tablespace
    ... My intention is the thro all the data away so would delete from ... tablename have the same restriction with constraints as truncate? ... Plus, TRUNCATE ...
    (comp.databases.oracle.server)
  • Re: DTS in SQL 2005 on tables with constraints
    ... constraints in between running the scripts and actually generating the ... script to have the ALTER TABLEs to reinstate the constraints is a pain ... I thought that EXEC sp_msforeachtable "ALTER TABLE ... NOCHECK CONSTRAINT all" might do the trick, but you can't TRUNCATE ...
    (microsoft.public.sqlserver.dts)
  • Re: truncate table - with foreign key constraints
    ... TRUNCATE is simply not allowed with foreign key constraints in place. ... You'll need to go through the trouble for dropping and recreating the ...
    (microsoft.public.sqlserver.server)
  • Re: how to boost drop table statement
    ... >>>You could try to TRUNCATE the tables first, but then they must not have ... >>>foreign key constraints. ... Assuming no cross-referencing referential integrity, ... * FirstSQL/J Object/Relational DBMS ...
    (comp.lang.java.databases)
  • RE: Having a stored procedure copy tables & also preserve indexing/sch
    ... INTO <tablename> doesn't create any of the PRIMARY KEY, UNIQUE, ... > that table with another that resides on a different database. ... > indexing/foriegn key constraints. ...
    (microsoft.public.sqlserver.mseq)