--    query: The query field provides a query of the top 10 rows, for the given table.  
--            The column in focus is put at the beginning of the query.
--    schema_name:  The schema_name provides the name of the schema of the table, it is often a dbo.
--    table_name: This indicates the name of the given table.
--    column_name:  This indicates the name of the given column.
--    column_id: This is the column id for the object and indicates the order the column appears in the table.  
--            Where the column id is 1, it is the first in the given table.
--    column_length:  This indicates the size of the column (data type).
--    column_percision: This indicates the size of the column (data type).
--    column_nullable: This indicates that the column is nullable or not (0: false; 1: true).
--    column_typename: This indicates the data type of a given field. 

With Object_CTE As (
    SELECT 
        object_name = name ,
        table_id = object_id ,
        Schema_Name = Schema_Name(schema_id),
        TYPE object_type , REPLACE (type_desc, '_', ' ') object_description
    FROM sys . objects
),
Field_CTE As (
    SELECT 
           table_id = object_id ,
           field_name =  name ,
           field_id =  column_id ,
           type_id =  system_type_id ,
           field_length =  max_length ,
           field_nullable =  is_nullable ,
           field_precision = PRECISION , 
           field_direction = NULL 
      FROM sys.columns columns
      UNION 
      SELECT object_id,
            name,
            parameter_id,
            system_type_id type_id,
            max_length,
            has_default_value,
            PRECISION,
            parameter_field
      FROM sys . PARAMETERS
      Cross Apply (
        Select parameter_field 
            =    CASE WHEN PARAMETERS.is_readonly = 1 THEN 'Readonly' 
                    ELSE '' END + ' ' + CASE WHEN PARAMETERS.is_output = 1 THEN 'Out' ELSE '' END + ' ' + 
                CASE WHEN PARAMETERS.is_xml_document = 1 THEN 'Xml Document' 
                    ELSE '' END
      ) parameter 
),
Query_CTE As (
    SELECT 
        query, schema_name, object_name,
        object_description,
        field_name, field_id, field_length, field_precision,
        field_nullable, field_typename, field_discriptor
    FROM
        Object_CTE
    LEFT JOIN Field_CTE ON Field_CTE.table_id = Object_CTE.table_id
    Cross Apply (
        Select 
            query = 
                CASE 
                    WHEN object_type IN('U', 'S', 'V') THEN 
                    'select top 10 ' + field_name + ', * from [' + SCHEMA_NAME + '].[' + object_name + ']' 
                END,
            field_typename =
                CASE
                    WHEN Type_Name(type_id) LIKE '%char' THEN Type_Name(type_id) + CASE
                    WHEN field_length = 1 THEN ''
                    WHEN field_length = - 1 THEN ' (max) '
                    ELSE ' (' + CAST (field_length AS varchar (10)) + ') '
                END
                    ELSE Type_Name(type_id)
                END + 
                CASE
                    WHEN ISNULL (field_nullable, 1) = 1 THEN ' null '
                    ELSE ''
                END,
            field_discriptor = 
                CASE
                    WHEN RTrim (field_direction) = '' THEN NULL
                    ELSE field_direction
                END 
    ) CrossApply
)
SELECT *
FROM Query_CTE 
ORDER BY object_name, field_id