/*<OXADWDB>*/
/*req only on OXADWDB DB*/

/*Removing default values for datetime 1*/
drop table if exists #TEMP_tmp_remove_defaults

<SEPARATEUR>
/*Removing default values for datetime 2*/ 
SELECT 
    dc.name AS ConstraintName,
	dc.definition,
    c.name AS ColumnName,
	'ALTER TABLE ' + QUOTENAME(OBJECT_NAME(parent_object_id)) + ' DROP CONSTRAINT ' + QUOTENAME(dc.name) + ';' + CHAR(13) as req
	into #TEMP_tmp_remove_defaults
FROM 
    sys.default_constraints AS dc
JOIN 
    sys.columns AS c ON dc.parent_object_id = c.object_id AND dc.parent_column_id = c.column_id
WHERE 
    dc.parent_object_id = OBJECT_ID('DOCUMENTS')
	and dc.definition like '%19000101%'
	and c.name not in (select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='DOCUMENTS' and IS_NULLABLE='NO')

DECLARE @Sql NVARCHAR(MAX);
DECLARE Cur CURSOR LOCAL FAST_FORWARD FOR 
    (SELECT req      FROM #TEMP_tmp_remove_defaults  )

OPEN Cur
FETCH NEXT FROM Cur INTO @Sql

WHILE (@@FETCH_STATUS = 0)
BEGIN
    --Exec sp_executesql @Sql
	print @Sql
    EXEC ( @Sql )

    FETCH NEXT FROM Cur INTO @Sql 
END
CLOSE Cur
DEALLOCATE Cur;    