Saturday, March 25, 2017

How to get list of all tables in a databases in SQL Server


Sometimes there may be requirement of a user to get the list of all tables in a database which exists in the SQL database management studio. The user may use this list to populate a dropdown menu, create a checkbox list, etc.

To get the list of all tables in a database, the user can use any of the following methods:


Method 1:

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND TABLE_CATALOG = 'DB_Name';



Method 2:
                       
SELECT name
FROM sysobjects
WHERE xtype = 'U';



Method 3:

SELECT NAME FROM sys.tables;



Method 4:

EXEC sp_msforeachtable 'PRINT ''?''';



Method 5:

EXEC SP_TABLES;




Share This
Previous Post
Next Post

TekGrabs, established in 2017, is in the business of sharing Information. It provides news, articles and photos about the different technologies, inventions in different domains. Provides information on programming and databases.

0 comments: