• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1464
  • Last Modified:

Query in ISQL to export schema

Looking for the equivalent sybase select statement for the oracle statement below: This statement uses metadata to export the Table name, column name, data type & length, description/definition and all other attributes

SELECT OWNER,TABLE_NAME, COLUMN_NAME, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, NULLABLE, COLUMN_ID
FROM ALL_TAB_COLUMNS
where OWNER = 'ME'
0
rickwinterkorn
Asked:
rickwinterkorn
  • 2
1 Solution
 
tgenslerCommented:
This code was taken from simon walkers SQL workshop site on the internet.

/***************************************************************************

 sp__cols

 list columns in table without having to wade through sp_help's excess info

 Copyright 1992-1995 The SQL Workshop Ltd.      siwalker@cix.compulink.co.uk

 Who      When      Why
 ---------------------------------------------------------------------------
 npike      ???      created
 simon      5jul92      tidied up, add error handling
 simon      31jan96      update for release

****************************************************************************/

if exists(select * from master..sysdatabases where name = "sybsystemprocs")
      use sybsystemprocs
else
      use master
go

if exists(select * from sysobjects where name = "sp__cols" and type = "P")
      drop procedure sp__cols
go

create procedure sp__cols

      @objname      char(30)
as

/*
** This procedure copyright 1995 The SQL Workshop Ltd.
** The code is freely distributable, but please leave this comment intact.
** simon walker
** siwalker@cix.compulink.co.uk
*/

declare      @objid      int

select      @objid = id
from      sysobjects
where      name = @objname
and      type in ("U", "V", "S")

if @objid is NULL
begin
      print "Object is not a table or view in the current database."      
      return (1)
end

select      'column name'      = c.name,
      type            = t.name,
      length            = c.length,
      prec            = c.prec,
      scale            = c.scale,
      nulls            = convert(bit, (c.status & 8)),
      'default name'      = object_name(c.cdefault),
      'rule name'      = object_name(c.domain),
      ident            = convert(bit, (c.status & 0x80))
from      syscolumns c,
      systypes t
where      c.id = @objid
and      c.usertype *= t.usertype

return (0)

go

grant execute on sp__cols to public
go


0
 
rickwinterkornAuthor Commented:
Thanks for the effort tgensler, however it didn't work.

0
 
rickwinterkornAuthor Commented:
Answer - I wrote the following code and it works very well,
thought I'd share it.

select T.creator, C.tname, C.colno, C.cname, C.coltype,C.length,C.in_primary_key, C.nulls, C.remarks
from SYSCOLUMNS C, SYSTABLE T
where Trim(C.creator) = 'DBA'
and Trim(C.tname) = Trim(T.table_name);

output to c:\DirName\FileName.txt
format ascii;
0
 
ajith_29Commented:
Hi rick,
This script will do the work for you

select Table_name = o.name ,
       Column_name= c.name,
          Data_type   = t.name,
             Length = c.length,
             Prec = c.prec,
             Scale = c.scale,
             Nulls = convert(bit, (c.status & 8))
            from syscolumns c, systypes t,sysobjects o
            where c.id <>0 and c.id = o.id and o.type = 'U'
                  and c.usertype *= t.usertype



Regards
Ajith
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now