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

前端 未结 12 851
刺人心
刺人心 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:27

    If Sybase is SQL-92 compliant then this information is stored within the INFORMATION_SCHEMA tables.

    So the following will give you a list of tables and views in any SQL-92 compliant database

    SELECT TABLE_NAME
    FROM INFORMATION_SCHEMA.TABLES
    
    0 讨论(0)
  • 2020-12-07 12:28

    When finding user table, in case if want the table owner name also, you can use the following:

    select su.name + '.' + so.name
    from   sysobjects so,
           sysusers   su
    where  so.type = 'U' and
           so.uid  = su.uid
    order  by su.name,
              so.name
    
    0 讨论(0)
  • 2020-12-07 12:30

    Check sysobjects and syscolumns tables.

    Here is a diagram of Sybase system tables.

    List of all user tables:

    SELECT * FROM sysobjects WHERE type = 'U'
    

    You can change 'U' to other objects:

    • C – computed column
    • D – default
    • F – SQLJ function
    • L – log
    • N – partition condition
    • P – Transact-SQL or SQLJ procedure
    • PR – prepare objects (created by Dynamic SQL)
    • R – rule
    • RI – referential constraint
    • S – system table
    • TR – trigger
    • U – user table
    • V – view
    • XP – extended stored procedure

    List of columns in a table:

    SELECT sc.* 
    FROM syscolumns sc
    INNER JOIN sysobjects so ON sc.id = so.id
    WHERE so.name = 'my_table_name'
    
    0 讨论(0)
  • 2020-12-07 12:31

    For Sybase ASE, sp_columns table_name will return all the table metadata you are looking for.

    0 讨论(0)
  • 2020-12-07 12:32

    You can search for column in all tables in database using:

    SELECT so.name 
    FROM sysobjects so
    INNER JOIN syscolumns sc ON so.id = sc.id 
    WHERE sc.name = 'YOUR_COLUMN_NAME'
    
    0 讨论(0)
  • 2020-12-07 12:36

    In the Sybase version I use, the following gives list of columns for selected table

    select *
    FROM sys.syscolumns sc
    where tname = 'YOUR_TABLE_NAME'
    --and creator='YOUR_USER_NAME' --if you want to further restrict tables
    --according to the user name that created it
    
    0 讨论(0)
提交回复
热议问题