From a Sybase Database, how I can get table description ( field names and types)?

前端 未结 12 883
刺人心
刺人心 2020-12-07 11:46

I have access to command line isql and I like to get Meta-Data of all the tables of a given database, possibly in a formatted file. How I can achieve that?

Thanks.

12条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 12:15

    sp_help is what you're looking for.

    From Sybase online documentation on the sp_help system procedure:

    Description

    Reports information about a database object (any object listed in sysobjects) and about system or user-defined datatypes, as well as computed columns and function-based indexes. Column displays optimistic_index_lock.

    Syntax

    sp_help [objname]

    [...]

    Here is the (partial) output for the publishers table (pasted from Using sp_help on database objects):

    Name               Owner        Object_type     Create_date 
    ----------------   -----------  -------------   ------------------------------
    publishers         dbo          user table      Nov 9 2004 9:57AM
    
    (1 row affected)
    Column_name Type     Length   Prec  Scale   Nulls   Default_name   Rule_name
    ----------- -------  ------   ----- ------- ------- -------------- ---------- 
    pub_id      char          4    NULL  NULL        0  NULL           pub_idrule
    pub_name    varchar      40    NULL  NULL        1  NULL           NULL
    city        varchar      20    NULL  NULL        1  NULL           NULL
    state       char          2    NULL  NULL        1  NULL           NULL
    Access_Rule_name    Computed_Column_object     Identity
    ------------------- -------------------------  ------------
    NULL                NULL                                  0
    NULL                NULL                                  0
    NULL                NULL                                  0
    NULL                NULL                                  0
    

    Still quoting Using sp_help on database objects:

    If you execute sp_help without supplying an object name, the resulting report shows each object in sysobjects, along with its name, owner, and object type. Also shown is each user-defined datatype in systypes and its name, storage type, length, whether null values are allowed, and any defaults or rules bound to it. The report also notes if any primary or foreign key columns have been defined for a table or view.

提交回复
热议问题