Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up
Get field name, data type and size of database table

Get field name, data type and size of database table

Intermediate 2 min read 18 Sep 2025 62.7K views
Get field name, data type and size of database table

Get field name, data type, and size of database table: An Overview

Knowing your table's structure is essential in the huge world of databases. By exploring SQL Server Tutorial, we can find out what each field's secret is. We can discover their names, data kinds (such as text, dates, or numbers), and even storage capacities with a few lines of code.

SQL Server skills can boost your earning potential by 22% in the next 3 years. Enroll in our Free SQL Server Course with Certificate today!

Read More - SQL Interview Questions And Answers

Read More - Commonly Asked DBMS Interview Questions

Query to get field name with datatype and size

A particular SQL query extracts key details about a table's fields, including their names, the types of data they hold (text, integers, dates, etc.), and the storage sizes allotted to them. You can more easily understand table structure, optimize queries, and do data analysis with this information.

SELECT column_name as 'Column Name', data_type as 'Data Type',
character_maximum_length as 'Max Length'
FROM information_schema.columns
WHERE table_name = 'tblUsers' 

This SQL query retrieves the column names, data types, and maximum lengths from a particular database named "tblUsers" and displays the results in an easy-to-read manner. Accessing a unique database view named "information_schema.columns," which contains metadata about tables and their columns, allows it to accomplish this.

Read More:

Summary

You may discover the names, types, and amounts of hidden data in your tables using the simple power of SQL queries. This understanding is essential for optimizing queries, mastering data analysis, and confidently navigating the complex world of SQL Server.

Full-Stack .NET Developers earn up to ₹35 LPA in India’s tech boom. Kickstart your high-paying career with our full stack .NET developer course today!

Frequently asked questions

How to get table column data type in SQL Server?
Details about a specific table column (e.g., column name, column ID, column data type, column restrictions) can be acquired in SQL Server by connecting system tables like sys. tables, sys. columns, and sys. types.
How to get database name and size in SQL Server?
If you only need to verify a single database, SQL Server Management Studio (SSMS) can rapidly ascertain the SQL Server database size: Right-click the database and select Reports -> Standard Reports -> Disc Usage from the menu. To obtain database size, you may also use stored procedures such as exec sp_spaceused.
What is the datatype of a column in SQL?
A column's data type determines what values it can store: integer, character, money, date and time, binary, and so on.
How to check column size in SQL?
To get the length of a column in SQL Server, use the COL_LENGTH() function. More specifically, the function returns the column's defined length in bytes. The function takes two arguments: the name of the table and the name of the column.
How do I get column names in SQL?
You can pick COLUMN_NAME from INFORMATION_SCHEMA. COLUMNS in SQL Server. It will determine whether the given table is a Base Table. This will display all of your column names in a single column.
Test yourself in 5 minutes

Take the free Sqlserver skill challenge to see your strengths and the gaps to fix next.

Start the challenge
Share LinkedIn X Facebook WhatsApp

About the author

Shailendra Chauhan

Shailendra Chauhan

Microsoft MVP, Founder & CEO at ScholarHat

He is a renowned Speaker, Solution Architect, Mentor, and 11-time Microsoft MVP (2016–2026). With expertise in AI/ML, GenAI, System Design, Azure Cloud, .NET, Angular, React, Node.js, Microservices, DevOps, and Cross-Platform Mobile App Development, he bridges traditional frameworks with next-gen innovations.

He has trained 1 Lakh+ professionals across the globe, authored 45+ bestselling eBooks and 1000+ technical articles, and mentored 20+ free courses. As a corporate trainer for leading MNCs like IBM, Cognizant, and Dell, Shailendra continues to deliver world-class learning experiences through technology & AI.

Keep learning

Courses that go with this tutorial