Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the tables names?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I only know the name of a database and I want to know the name of each table in the database ant the name of each row (field) in each table. Is an SQL query able to do that? Which one?
 
I assume you are using SQL Server 6.5 or 7.0

- launch i-sql/query analyzer
- choose the database

and type

sp_help

or

select * from sysobjects where xtype = 'U'

hope it helps!

 

The following query will list the tables and views in a database.

Select * From dbname.information_schema.tables

The following query will list the columns in a database.

Select * From dbname.information_schema.columns

You can read more about the INFORMATION_SCHEMA views in SQL Books Online (BOL).

BTW: Microsoft recommends using the INFORMATION_SCHEMA Views rather than querying system tables. However, I prefer this query to list just user defined tables.

Select * From sysobjects where type='u' Terry
------------------------------------
Blessed is the man who, having nothing to say, abstains from giving us worthy evidence of the fact. -George Eliot
 
select tables=a.name, columns=b.name from sysobjects a join syscolumns b on a.id=b.id WHERE a.type='U'

This will be helpful.
 
I didn't use this commands for a long time, but I remember that:

1. sp_tables and sp_tables_ex, which are built-in stored procedures, return a recordset containing data about the tables in a database.

2.If you will get a security problem,when you use the above SPs you have to call first sp_dboption with a specific option that now I don't remeber right now.

Hope this will be of some help, s-) Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top