Solved

Generating SQL using ASA9

Posted on 2006-06-29
6
305 Views
Last Modified: 2008-03-10
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...
Thanks
M
0
Comment
Question by:mahalakshmi_s
  • 3
  • 2
6 Comments
 
LVL 24

Expert Comment

by:Joe Woodhouse
ID: 17015339
Sybase Central (shipped with ASA) can do this for you. Right click on the table and you should see something about "Generate DDL".
0
 

Author Comment

by:mahalakshmi_s
ID: 17017548
Am sorry Joe, I could not find "Generate DDL" at all :-(((((
any other way...its urgent
0
 
LVL 24

Expert Comment

by:Joe Woodhouse
ID: 17018310
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...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:mahalakshmi_s
ID: 17019381
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

0
 
LVL 24

Expert Comment

by:Joe Woodhouse
ID: 17021786
That won't give you the SQL but it's a good start. 8-)
0
 
LVL 14

Accepted Solution

by:
Jan_Franek earned 500 total points
ID: 17031178
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
)
as
  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=""
  else
    select @default=text
      from dbo.syscomments
        where id=@obj_id
          and colid=1
go

create procedure sp_ddl_user_table_columns
(
    @table_id int
)
as
  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),
      @i=1
    from dbo.syscolumns
      where id=@table_id
  declare cr cursor for
    select c.name,c.usertype,t.name,c.status,c.length,c.prec,c.scale,c.cdefault
      from dbo.syscolumns c, dbo.systypes t
        where c.id=@table_id
          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
  begin
    select @nulltype=case
        when @status & 128 = 128 then "identity not null"
        when @status & 8 = 8 then "null"
        else "not null"
      end,
      @type_name=case
        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
      end,
      @text="  %1! %2! %3! %4!"+case when @i=@c then "" else "," end,
      @i=@i+1
    select @colname=@col_name,
      @typename=@type_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
  end

  close cr
  deallocate cursor cr


go

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Scenario: Your operations manager has discovered an anomaly in your security system. The business will start to suffer within 15 minutes if it is a major IT incident. What should she do? We have 6 recommendations for managing major incidents (https:…
An analysis of the phishing scam that has been affecting Google users, along with steps to take for protection, as well as what to do if you receive one of the emails.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now