why drop constraints before truncate
From: Thomas Scheiderich (tfs_at_deltanet.com)
Date: 04/29/04
- Next message: Bojidar Alexandrov: "Re: Dynamic SQL"
- Previous message: Sohail: "Dynamic SQL"
- Next in thread: Bojidar Alexandrov: "Re: why drop constraints before truncate"
- Reply: Bojidar Alexandrov: "Re: why drop constraints before truncate"
- Reply: DBA72: "RE: why drop constraints before truncate"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 28 Apr 2004 23:03:14 -0700
I have a SP that removes the foreign keys, then truncates some files and
then adds back the keys.
Why do this?
For example:
**********************************************************************************
ALTER TABLE dbo.SalesFact DROP CONSTRAINT FK_SalesCustomer
ALTER TABLE dbo.SalesFact DROP CONSTRAINT FK_SalesProduct
ALTER TABLE dbo.SalesFact DROP CONSTRAINT FK_SalesTime
GO
TRUNCATE TABLE dbo.SalesFact
TRUNCATE TABLE dbo.SalesStage
TRUNCATE TABLE dbo.CustomerDim
TRUNCATE TABLE dbo.ProductDim
GO
ALTER TABLE dbo.SalesFact ADD
CONSTRAINT FK_SalesCustomer FOREIGN KEY
(CustomerKey) REFERENCES dbo.CustomerDim (CustomerKey)
,CONSTRAINT FK_SalesProduct FOREIGN KEY
(ProductKey) REFERENCES dbo.ProductDim (ProductKey)
,CONSTRAINT FK_SalesTime FOREIGN KEY
(TimeKey) REFERENCES dbo.TimeDim (TimeKey)
*********************************************************************************
Also, if I am going to do a large amount of inserts (say about 500,000
or more), would it be better to do the inserts first and then put the
keys back at that time?
Thanks,
Tom.
- Next message: Bojidar Alexandrov: "Re: Dynamic SQL"
- Previous message: Sohail: "Dynamic SQL"
- Next in thread: Bojidar Alexandrov: "Re: why drop constraints before truncate"
- Reply: Bojidar Alexandrov: "Re: why drop constraints before truncate"
- Reply: DBA72: "RE: why drop constraints before truncate"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|