dump tran sybsystemprocs with truncate_only
go

use sybsystemprocs
go

if exists (select * from sysobjects where name = "sp_describe" and type = 'P')
   drop proc sp_describe
go

CREATE PROCEDURE sp_describe @tab char(30) = NULL
AS

/* This procedure is a nicely formatted sp_help  procedure */

        IF (@tab is NULL)
                RAISERROR 22000 "Must specify table name for describe!"
        ELSE
                DECLARE @min_id int

                SELECT C.colid 'column_id', C.name 'column_name',
                        T.name 'column_type', C.length 'column_length',
                        C.status 'column_is_null',
                        C.prec 'prec', C.scale 'scale'
                INTO #tab_descr
                FROM syscolumns C, sysobjects O, systypes T
                WHERE C.id = O.id
                AND C.usertype = T.usertype
                AND O.name = @tab

                UPDATE  #tab_descr
                SET column_type = "char("+LTRIM(RTRIM(str(column_length)))+")"
                WHERE   column_type = "char"

                UPDATE  #tab_descr
                SET column_type="varchar("+LTRIM(RTRIM(str(column_length)))+")"
                WHERE   column_type = "varchar"

                UPDATE  #tab_descr
                SET column_type="numeric(" + LTRIM(RTRIM(str(prec))) + "," + 
                         LTRIM(RTRIM(str(scale))) + ")"
                WHERE   column_type = "numeric"

                UPDATE  #tab_descr
                SET column_type="decimal(" + LTRIM(RTRIM(str(prec))) + "," + 
                         LTRIM(RTRIM(str(scale))) + ")"
                WHERE   column_type = "decimal"

                UPDATE  #tab_descr
                SET column_type="float(" + LTRIM(RTRIM(str(prec))) + ")"
                WHERE   column_type = "float"

                UPDATE #tab_descr
                SET column_type = column_type + ", NOT NULL"
                WHERE convert(bit, (column_is_null & 8)) = 0

                UPDATE #tab_descr
                SET column_type = column_type + ", IDENT"
                WHERE convert(bit, (column_is_null & 0x80)) = 1

                SELECT @min_id = min(column_id)
                FROM #tab_descr

                UPDATE #tab_descr
                SET column_id = column_id - @min_id + 1

                PRINT @tab

        SELECT CONVERT(char(6), "("+LTRIM(str(column_id))+")") 'No.', 
                        CONVERT(char(25), column_name) 'Column Name',
                        column_type 'Type'
                FROM    #tab_descr
                ORDER BY column_id
 
go

if object_id('sp_describe') is not null
begin
    print '<<< Created procedure dbo.sp_describe >>>'
    grant execute on dbo.sp_describe to public
end
else
begin
    print '<<< Failed creating proc dbo.sp_describe >>>'
end
go