Example program DatabaseTree, shown in Figure 1, connects to a database server. This program connects to a server named BENDER\NetSDK. You should modify the code to log on to your server with your user name and password.
Figure 1 Program DatabaseTree lists the databases, tables, and fields in a SQL Server.
The program then uses the sp_databases stored procedure to list the server's databases.
For each database, the program calls the sp_tables procedure to list the database's tables. For each table in the database, the program calls the sp_columns stored procedure to get column information. It displays the column's name, the length if it is a string, and an indication of whether the field can be NULL. Click back to the data creation scripts near the beginning of this article to verify that the program correctly described the Students and TestScores tables in Figure 1.
The details of the program are a bit much to explain here, but you can download the code, and look at it for yourself. Click here to download the DatabaseTree program. The code isn't terribly complicated, just a bit long.