USE your database name
GO
DECLARE @tblFKConstraints TABLE (RecordID INT IDENTITY(1,1), DropScript VARCHAR(500))
DECLARE
@SQL VARCHAR(500),
@MaxID INT,
@MinID INT
INSERT INTO @tblFKConstraints
SELECT 'ALTER TABLE ' + TABLE_NAME + ' Drop Constraint ' + CONSTRAINT_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
SELECT @MinID = MIN(RecordID), @MaxID = MAX(RecordID) FROM @tblFKConstraints
WHILE @MinID <= @MaxID
BEGIN
SELECT @SQL = DropScript FROM @tblFKConstraints WHERE RecordID = @MinID
EXEC (@SQL)
SET @MinID = @MinID + 1
END
GO
DECLARE @tblFKConstraints TABLE (RecordID INT IDENTITY(1,1), DropScript VARCHAR(500))
DECLARE
@SQL VARCHAR(500),
@MaxID INT,
@MinID INT
INSERT INTO @tblFKConstraints
SELECT 'ALTER TABLE ' + TABLE_NAME + ' Drop Constraint ' + CONSTRAINT_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
SELECT @MinID = MIN(RecordID), @MaxID = MAX(RecordID) FROM @tblFKConstraints
WHILE @MinID <= @MaxID
BEGIN
SELECT @SQL = DropScript FROM @tblFKConstraints WHERE RecordID = @MinID
EXEC (@SQL)
SET @MinID = @MinID + 1
END
No comments:
Post a Comment