Search code examples
sql-serverinformation-schema

Get all information schema from Database tables


How can I limit the following query to return for only tables in the database and exclude views?

USE [Database Name] SELECT * FROM INFORMATION_SCHEMA.COLUMNS

Solution

  • Microsoft discourages the use of INFORMATION_SCHEMA. The way to do it if you don't want to use the sys views:

    SELECT  * 
    FROM    INFORMATION_SCHEMA.COLUMNS AS C
    INNER JOIN INFORMATION_SCHEMA.TABLES AS T
            ON  T.TABLE_SCHEMA = C.TABLE_SCHEMA
            AND T.TABLE_NAME = C.TABLE_NAME
    WHERE       T.TABLE_TYPE = 'BASE TABLE'