SET QUOTED_IDENTIFIER ON
GO 
 
-- Drop Triggers
Declare @recstr varchar(255)
Declare @DropStmt varchar(255)
Declare c cursor
FORWARD_ONLY 
FOR SELECT 
 name from dbo.sysobjects where OBJECTPROPERTY(id, N'IsTrigger') = 1 and category=0
 
OPEN c
FETCH NEXT FROM c INTO @recstr
 WHILE @@FETCH_STATUS = 0
 BEGIN
  SET @DropStmt = ('DROP TRIGGER ' + @recstr)
--  print @DropStmt
  exec (@DropStmt)
  FETCH NEXT FROM c INTO @recstr
 END
CLOSE c
DEALLOCATE c
GO

/* MODIFICATION ZONE START:CINSDAO-DropIndexes */
/* MODIFICATION ZONE END:CINSDAO-DropIndexes */


-- Drop all non-primary Constraints
Declare @recstr varchar(255)
Declare @parentID int
Declare @parentTable varchar(255)
Declare @DropStmt varchar(255)
Declare c cursor
FORWARD_ONLY 
FOR
 SELECT name, parent_obj from dbo.sysobjects 
 WHERE OBJECTPROPERTY(id, N'IsConstraint') = 1 
 AND category=0
 AND OBJECTPROPERTY(id, N'IsPrimaryKey') = 0

OPEN c
FETCH NEXT FROM c INTO @recstr, @parentID
 WHILE @@FETCH_STATUS = 0
 BEGIN
  SET @parentTable = (SELECT name from dbo.sysobjects where OBJECTPROPERTY(id, N'IsTable') = 1 and id=@parentID)
  SET @DropStmt = ('ALTER TABLE '+ @parentTable + ' DROP CONSTRAINT ' + @recstr)
--  print @DropStmt
  exec (@DropStmt)
  FETCH NEXT FROM c INTO @recstr, @parentID
 END
CLOSE c
DEALLOCATE c
GO

-- Drop Unique Indexes
Declare @recstr varchar(255)
Declare @parentID int
Declare @parentTable varchar(255)
Declare @DropStmt varchar(255)
Declare c cursor
FORWARD_ONLY 
FOR
SELECT 
si.name, si.id from dbo.sysindexes [si] INNER JOIN  dbo.sysobjects [so] on so.id = si.id 
where OBJECTPROPERTY(so.id, N'IsUserTable') = 1 
AND INDEXPROPERTY(so.id, si.name, N'IsClustered') = 0
AND INDEXPROPERTY(so.id, si.name, N'IsStatistics') = 0
AND indid > 1 AND indid < 255
OPEN c
FETCH NEXT FROM c INTO @recstr, @parentID
 WHILE @@FETCH_STATUS = 0
 BEGIN
  SET @parentTable = (SELECT name from dbo.sysobjects where OBJECTPROPERTY(id, N'IsUserTable') = 1 and id=@parentID)
  SET @DropStmt = ('DROP INDEX '+ @parentTable + '.' + @recstr)
  --print @DropStmt
  exec (@DropStmt)
  FETCH NEXT FROM c INTO @recstr, @parentID
 END
CLOSE c
DEALLOCATE c
GO

