Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the list of user defined tables in the specific database

Tags:

java

sql

sybase

I need to list the name of all tables in the specific database in sybase and then filter these table name according some string in the name.

This gives current database but I can't specify specific database:

select name from sysobjects where type = 'U'

This gives more than tables, it includes trigger and stored procedure:

Select name from sysobjects
WHERE db_name()='pad_orr_db'

Does any body know how to do it and also filter the name of tables by some string in the name for example only the table with the SASSA in the name be displayed?

like image 856
michdraft Avatar asked Feb 02 '26 08:02

michdraft


1 Answers

Use sp_tables.

sp_tables [table_name] [, table_owner] 
    [, table_qualifier][, table_type]

where *table_qualifier* is the name of the database.

Tables and Views

To get all tables, views, and system tables, the following Sybase system stored procedure can be executed.

exec sp_tables '%'

To filter by database for tables only, for example master:

exec sp_tables '%', '%', 'master', "'TABLE'"

To filter by database and owner / schema for tables only, for example, master and dbo:

exec sp_tables '%', 'dbo', 'master', "'TABLE'"

To return only views, replace "'TABLE'" with "'VIEW'". To return only system tables, replace "'TABLE'" with "'SYSTEM TABLE'".

like image 146
Sajal Dutta Avatar answered Feb 04 '26 21:02

Sajal Dutta