Generating SQL using ASA9

I created a table with 150 columns using interface in ASA9. Now my DBA wants the SQL of CREATE TABLE.
I dont have time to code and give him the SQL as every column name is lengthy too.
Also I may add, 40 more columns in future.
Is there anyway, I can generate SQL for my existing table ? Kindly help...
Who is Participating?
Jan FranekConnect With a Mentor Commented:
here is the procedure, that i use to generate table ddl - it works in ASE, may be it will need some adjustmensts for ASA:

create procedure sp_ddl_get_default
    @obj_id int,
    @default varchar(255) output
  if isnull(@obj_id,0)=0
    select @default=""
  else if not exists  ( select 1 from dbo.sysobjects
                          where id=@obj_id
                            and type="D"
                            and name like "%"+convert(varchar(20),@obj_id) )
    select @default=""
    select @default=text
      from dbo.syscomments
        where id=@obj_id
          and colid=1

create procedure sp_ddl_user_table_columns
    @table_id int
  declare @col_name varchar(30),
    @type_id int,
    @type_name varchar(30),
    @status tinyint,
    @length int,
    @cdefault int,
    @prec tinyint,
    @scale tinyint,
    @i tinyint,
    @c tinyint,
    @nulltype varchar(20),
    @colname varchar(30),
    @typename varchar(30),
    @default varchar(255),
    @text varchar(255)

  select @c=count(1),
    from dbo.syscolumns
      where id=@table_id
  declare cr cursor for
      from dbo.syscolumns c, dbo.systypes t
          and c.usertype=t.usertype
        order by c.colid
    for read only

  open cr
  fetch cr into @col_name,@type_id,@type_name,@status,@length,@prec,@scale,@cdefault
  while @@sqlstatus=0
    select @nulltype=case
        when @status & 128 = 128 then "identity not null"
        when @status & 8 = 8 then "null"
        else "not null"
        when @type_id>=100 then @type_name
        when @prec is not null then @type_name+"("+convert(varchar(3),@prec)+","+convert(varchar(3),@scale)+")"
        when @type_name in ("binary","char","varbinary","varchar") then @type_name+"("+convert(varchar(3),@length)+")"
        else @type_name
      @text="  %1! %2! %3! %4!"+case when @i=@c then "" else "," end,
    select @colname=@col_name,
    exec sp_ddl_get_default @cdefault, @default output
    print @text,@colname,@typename,@default,@nulltype
    fetch cr into @col_name,@type_id,@type_name,@status,@length,@prec,@scale,@cdefault

  close cr
  deallocate cursor cr


Joe WoodhousePrincipal ConsultantCommented:
Sybase Central (shipped with ASA) can do this for you. Right click on the table and you should see something about "Generate DDL".
mahalakshmi_sAuthor Commented:
Am sorry Joe, I could not find "Generate DDL" at all :-(((((
any other way...its urgent
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Joe WoodhousePrincipal ConsultantCommented:
Sorry, I don't have a copy of ASA to check exactly where it's Sybase Central puts its commands. (Sybase has an unfortunate habit of not standardising the various Sybase Central versions for their different products...) If you have Sybase Central for ASA, it's there somewhere...
mahalakshmi_sAuthor Commented:
Sorry I couldnot find out any...
I was planning to use the foll command as of now...

select cname,coltype,length,nulls from sys.syscolumns where tname='#rps_500_temp' order by colno;
output to c:\#rps_500_temp.txt

Joe WoodhousePrincipal ConsultantCommented:
That won't give you the SQL but it's a good start. 8-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.