DECLARE @sql NVARCHAR(MAX)
IF EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'LastUpdDateStamp'
    WHERE SysObjects.Name = 'Reservations'
)
BEGIN
 
	WHILE 1=1
	BEGIN
		SELECT TOP 1 @sql = N'alter table reservations drop constraint ['+dc.NAME+N']'
		from sys.default_constraints dc
		JOIN sys.columns c
			ON c.default_object_id = dc.object_id
		WHERE 
			dc.parent_object_id = OBJECT_ID('Reservations')
		AND c.name = N'LastUpdDateStamp'
		IF @@ROWCOUNT = 0 BREAK
		EXEC (@sql)
	END

	IF EXISTS( select * from sys.indexes WHERE NAME = 'IX_Reservations_LastUpdDateStamp')
		DROP INDEX IX_Reservations_LastUpdDateStamp ON Reservations

	ALTER TABLE Reservations DROP COLUMN LastUpdDateStamp
END
SET @SQL = ''
IF EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'DoSendMail'
    WHERE SysObjects.Name = 'Reservations'
)
BEGIN
	WHILE 1=1
	BEGIN
		SELECT TOP 1 @sql = N'alter table reservations drop constraint ['+dc.NAME+N']'
		from sys.default_constraints dc
		JOIN sys.columns c
			ON c.default_object_id = dc.object_id
		WHERE 
			dc.parent_object_id = OBJECT_ID('Reservations')
		AND c.name = N'DoSendMail'
		IF @@ROWCOUNT = 0 BREAK
		EXEC (@sql)
	END
	ALTER TABLE Reservations DROP COLUMN DoSendMail
END

SET @SQL = ''
IF EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'SendMailTemplateDefaultType'
    WHERE SysObjects.Name = 'Reservations'
)
BEGIN
	WHILE 1=1
	BEGIN
		SELECT TOP 1 @sql = N'alter table reservations drop constraint ['+dc.NAME+N']'
		from sys.default_constraints dc
		JOIN sys.columns c
			ON c.default_object_id = dc.object_id
		WHERE 
			dc.parent_object_id = OBJECT_ID('Reservations')
		AND c.name = N'SendMailTemplateDefaultType'
		IF @@ROWCOUNT = 0 BREAK
		EXEC (@sql)
	END
	ALTER TABLE Reservations DROP COLUMN SendMailTemplateDefaultType
END

