quarta-feira, dezembro 08, 2004
NC MS SQL Server 2000
Link
-- PROCEDURE to disable/enable all constraints on a table
CREATE PROCEDURE sp_ConstraintState
@TblName VARCHAR(128),
@State BIT = 1
AS
DECLARE @SQLState VARCHAR(500)
IF @State = 0
BEGIN
SET @SQLState = 'ALTER TABLE '+ @TblName + ' NOCHECK CONSTRAINT ALL'
END
ELSE
BEGIN
SET @SQLState = 'ALTER TABLE ' + @TblName + ' CHECK CONSTRAINT ALL'
END
EXEC (@SQLState)
go
-- For example: exec sp_ConstraintState 'products',0
will disable all constraints on the products table in northwind
-- PROCEDURE to disable/enable all constraints in an entire databse (using sp_constraintState)
CREATE proc sp_disable_all_const_in_db
as
exec sp_MsForEachTable 'sp_ConstraintState ''?'',0'
GO
to disbale all constraints in the database
EXEC sp_disable_all_const_in_db
Link
-- PROCEDURE to disable/enable all constraints on a table
CREATE PROCEDURE sp_ConstraintState
@TblName VARCHAR(128),
@State BIT = 1
AS
DECLARE @SQLState VARCHAR(500)
IF @State = 0
BEGIN
SET @SQLState = 'ALTER TABLE '+ @TblName + ' NOCHECK CONSTRAINT ALL'
END
ELSE
BEGIN
SET @SQLState = 'ALTER TABLE ' + @TblName + ' CHECK CONSTRAINT ALL'
END
EXEC (@SQLState)
go
-- For example: exec sp_ConstraintState 'products',0
will disable all constraints on the products table in northwind
-- PROCEDURE to disable/enable all constraints in an entire databse (using sp_constraintState)
CREATE proc sp_disable_all_const_in_db
as
exec sp_MsForEachTable 'sp_ConstraintState ''?'',0'
GO
to disbale all constraints in the database
EXEC sp_disable_all_const_in_db
Link