List Table Columns in SQL Server

Hello to everyone,
In this article, I will give you information about how to list the columns of the tables in the database in SQL Server.

Query below lists all table columns in a SQL Server database.

SELECT SCHEMA_NAME(tab.schema_id) AS schema_name,
       tab.name AS table_name,
       col.column_id,
       col.name AS column_name,
       t.name AS data_type,
       col.max_length,
       col.precision
FROM sys.tables AS tab
    INNER JOIN sys.columns AS col
        ON tab.object_id = col.object_id
    LEFT JOIN sys.types AS t
        ON col.user_type_id = t.user_type_id
ORDER BY schema_name,
         table_name,
         column_id;

When you run the code you will get the following result.

List Table Columns in SQL Server

As you can see, the tables and columns are listed with their data types.

Good luck to everyone in business and life.

418 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!