Querying Database Tables and Views

Sometimes your code needs to do more than just query data from the database.

Michael Otey

October 15, 2006

1 Min Read
ITPro Today logo in a gray background | ITPro Today

Sometimes your code needs to do more than just query data from the database. For example, you might want to query the structure and objects in the database. For this type of query, a basic approach is to query the available tables and views in your database. For example, to list the tables in the AdventureWorks database, use SQL Server Query Editor to execute the following code:

USE adventureworksGOSELECT * FROM sys.tablesGO

Sys.tables is a system database that stores the names of all the tables in the current database. Likewise, if you want a list of all the views in a database, use the sys.views system table by executing the following code:

USE adventureworksGOSELECT * FROM sys.viewsGO

 

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like