DECLARE @name VARCHAR(50)

DECLARE list_cursor CURSOR FAST_FORWARD FOR  
SELECT name FROM sys.objects
WHERE type = 'U' 
AND name LIKE 'custport%'
ORDER BY name

OPEN list_cursor  
FETCH NEXT FROM list_cursor INTO @name  

WHILE @@FETCH_STATUS = 0  
BEGIN 
    print @name
    DECLARE
	   @pk VARCHAR(100),
	   @uq VARCHAR(100),
	   @fkn VARCHAR(100),
	   @sql VARCHAR(max)

    SELECT @pk = name FROM sys.objects
    WHERE type = 'PK' AND  parent_object_id = OBJECT_ID (@name)

    SELECT @uq = name FROM sys.objects
    WHERE type = 'UQ' AND  parent_object_id = OBJECT_ID (@name)

    SELECT @fkn = COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @name AND ORDINAL_POSITION = 1

    -- drop UQ
    SET @sql = '
    BEGIN TRANSACTION
    SET QUOTED_IDENTIFIER ON
    SET ARITHABORT ON
    SET NUMERIC_ROUNDABORT OFF
    SET CONCAT_NULL_YIELDS_NULL ON
    SET ANSI_NULLS ON
    SET ANSI_PADDING ON
    SET ANSI_WARNINGS ON
    COMMIT
    BEGIN TRANSACTION
    GO
    ALTER TABLE dbo.'+@name+'
		  DROP CONSTRAINT '+@uq+'
    GO
    ALTER TABLE dbo.'+@name+' SET (LOCK_ESCALATION = TABLE)
    GO
    COMMIT';
    EXEC(@sql);

    -- drop PK
    SET @sql = '
    BEGIN TRANSACTION
    SET QUOTED_IDENTIFIER ON
    SET ARITHABORT ON
    SET NUMERIC_ROUNDABORT OFF
    SET CONCAT_NULL_YIELDS_NULL ON
    SET ANSI_NULLS ON
    SET ANSI_PADDING ON
    SET ANSI_WARNINGS ON
    COMMIT
    BEGIN TRANSACTION
    GO
    ALTER TABLE dbo.'+@name+'
		  DROP CONSTRAINT '+@pk+'
    GO
    ALTER TABLE dbo.'+@name+' ADD CONSTRAINT
	'+@pk+' PRIMARY KEY CLUSTERED 
	(
	'+@fkn+'
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    ALTER TABLE dbo.'+@name+' SET (LOCK_ESCALATION = TABLE)
    GO
    COMMIT';
    EXEC(@sql);

    FETCH NEXT FROM list_cursor INTO @name
END  

CLOSE list_cursor  
DEALLOCATE list_cursor 