• This is helpful, very nice. Thanks for sharing.

    It would appear this does not account for Extended Properties at the column level. Added this code to catch the extended properties for columns:

    SELECT @EXTENDEDPROPERTIES =

    @EXTENDEDPROPERTIES + @vbCrLf +

    'EXEC sys.sp_addextendedproperty

    @name = N''' + [name] + ''', @value = N''' + REPLACE(convert(varchar(max),[value]),'''','''''') + ''',

    @level0type = N''SCHEMA'', @level0name = [' + @SCHEMANAME + '],

    @level1type = N''TABLE'', @level1name = [' + @TBLNAME + '],

    @level2type = N''COLUMN'', @level2name = [' + [objname] + '];'

    --SELECT objtype, objname, name, value

    FROM fn_listextendedproperty (NULL, 'schema', @SCHEMANAME, 'table', @TBLNAME, 'column', NULL)

    Also there is no sorting on included columns in indexes.

    So I changed the line in the 2nd sub select in two queries

    from

    SELECT COLS.[name] + case when IXCOLS.is_descending_key = 0 then ' asc' else ' desc' end + ',' + ' '

    to

    SELECT COLS.[name] + ',' + ' '