michdraft
michdraft

Reputation: 556

Get the list of user defined tables in the specific database

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?

Upvotes: 3

Views: 17956

Answers (3)

Gopal Sanodiy
Gopal Sanodiy

Reputation: 91

Select name from db_name..sysobjects where  type ="U"

replace actual database name from db_name.

type 'U' is for user defined table.

Upvotes: 3

user115806
user115806

Reputation: 11

use <database_name>
go

select * from sysobjects where type='U'
go

This should list the user tables,stored procedures and proxy tables.

Upvotes: 1

Saj
Saj

Reputation: 18702

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'".

Upvotes: 4

Related Questions