Skip to content

Instantly share code, notes, and snippets.

@tjwudi

tjwudi/sybase-ase-cmd.md

Last active Aug 29, 2015
Embed
What would you like to do?

List all databases

sp_helpdb

Check the current database name

select d.name 
from master..sysdatabases d, master..sysprocesses p 
where d.dbid=p.dbid and p.spid=@@spid

List all user tables

SELECT * FROM sysobjects WHERE type = 'U'

List all columns in a table

SELECT sc.* 
FROM syscolumns sc
INNER JOIN sysobjects so ON sc.id = so.id
WHERE so.name = 'my_table_name'

Thanks to Lukasz Lysik's post on StackOverflow

Drop a database if exists

IF EXISTS (SELECT name FROM sysdatabases WHERE name = 'testdb')
BEGIN
    EXECUTE('DROP DATABASE testdb')
    print '[testdb] dropped'
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment