Thursday, June 29, 2017

SQL server - How to see the tables, columns and views




How to see the tables, columns and views from SQL server Database?

This Blog is for SQL beginners. The approach is to use “INFORMATION_SCHEMA” view to fetch list of tables/columns/views. Please see the below details for further details.



1.       To view list of all the tables using below command.

SELECT                 *             FROM                   INFORMATION_SCHEMA.TABLES

 



          SP_HELP "INFORMATION_SCHEMA.COLUMNS"
             




2.      To see list of fields of a table, use “INFORMATION_SCHEMA.COLUMNS” view. You can also use "SP_HELP '<tablename>' ", but the problem I faced with SP_HELP is the data type of few columns are not correct.



SELECT                 *             FROM                   INFORMATION_SCHEMA.COLUMNS
             



SP_HELP "INFORMATION_SCHEMA.COLUMNS"


              



3.      To see list of views, use “INFORMATION_SCHEMA.VIEW” view. You can see view script by using “VIEW_DEFINITION”.



   SELECT                        *             FROM                   INFORMATION_SCHEMA.VIEWS


             



SP_HELP "INFORMATION_SCHEMA.VIEW"

              




  

Please refer below link to understand more about “INFORMATION_SCHEMA” view.