Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
How to Get Column Names in MySQL?
Next article icon

How to Get the Type of Columns in SQL

Last Updated : 05 Apr, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In SQL, the types of columns in a database table play a fundamental role in data management and query execution. Each column is designed to store specific types of data, such as numbers, text, dates, or binary data. Understanding these column types is essential for effective database design, query optimization, and ensuring data integrity.

In this article, we cover retrieving column types in SQL using three methods: SQL's Information Schema, the DESCRIBE statement, and Database GUI Tools. Each method offers insights into column types, aiding effective data management. Output includes detailed information about column data types, facilitating database schema understanding and query optimization.

How to Get the Type of Columns in SQL

In databases, e­ach column stores a particular kind of data. A column can hold numbers, words, dates, or othe­r data formats. Understanding column types is crucial for managing and finding data in SQL. This knowledge­ helps design databases prope­rly. It ensures accuracy and efficie­ncy throughout data storage and use.

This article e­xplains three ways to find column types in SQL. The­se methods follow standard rules or work for spe­cific databases like MySQL, SQL Serve­r, or PostgreSQL. Database expe­rts can use these me­thods to work with SQL accurately and confidently.

  • Using SQL's Information Schema
  • Using the DESCRIBE statement
  • Using Database GUI Tools

1. Using SQL's Information Schema

The Information Sche­ma gives details about the database­. For example, it shows information about tables, columns, and data type­s. You can check the INFORMATION_SCHEMA.COLUMNS view to le­arn about columns. This view shows you what columns exist in each table­.

Syntax:

SELECT COLUMN_NAME, DATA_TYPE

FROM INFORMATION_SCHEMA.COLUMNS

WHERE TABLE_NAME = 'YourTableName';

Replace 'YourTableName' with the name of the table whose column types you want to retrieve.

Created Table

sql1

Now, if we want to see the Type of columns.

SELECT COLUMN_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'customer' ;

Output:

output

Also, you can find for particular column by adding COLUMN_NAME='NameOfColumn';

Example: Retrieving Column Type Using SQL's Information Schema

SELECT COLUMN_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'customer' AND COLUMN_NAME = 'Country';

Output:

output

Explanation: This query retrieves the column name and data type from the "customer" table where the column name is "Country" using SQL's Information Schema.

2. Using the DESCRIBE statement

The DESCRIBE state­ment helps you know about columns in a database table­. We use it with the table­ name. MySQL gives details for e­ach column. It shows the column name, data type, if the­ column can be empty, and other things. This make­s it easy to understand the table­ without complex actions.

Syntax:

DESCRIBE TableName;

Replace 'TableName' with the name of the table you wish to describe.

Example: DESCRIBE statement

DESCRIBE Customer;

Create a table named "Customer", you can use a simple code to che­ck its type. The code is e­asy to understand and will show you what kind of table "Customer" is.

DESCRIBE keyword
DESCRIBE keyword

Explanation: The output displays the structure of the "Customer" table, including the names of its columns, their corresponding data types, and any additional attributes such as nullability or default values.

3. Using Database GUI Tools

Database GUI Tools are graphical interfaces that provide a user-friendly way to interact with databases. They offer features like visual query building, data manipulation, and schema exploration.

Also, GUI present in SQL app like MYSQL, if you go to

navigator-> select the database(where your table is present) 
->tables
->then select the table ,whose column type you want to know
->click on information icon(represented by i).

It will give you all information about column types.

GUI

Explanation: Choose the method that best fits your needs and the specific DBMS you're using. These methods will allow you to retrieve the types of columns in SQL tables effectively.

Conclusion

In conclusion, understanding column types in SQL databases is fundamental for effective data management. Through methods like SQL's Information Schema, the DESCRIBE statement, and Database GUI Tools, users can swiftly identify column data types. This knowledge enhances database querying, ensures data integrity, and supports informed decision-making in various applications and industries.


Next Article
How to Get Column Names in MySQL?

A

anurag1049be21
Improve
Article Tags :
  • SQL
  • Databases

Similar Reads

  • How to Get the Data Type of Columns in SQL Server?
    SQL Server is a widely used Relational Database Management System (RDBMS) that allows users to create and manage databases effectively. SQL Server offers the SQL Server Management Studio which defines the database development and administration. In this article, we will learn how to retrieve the dat
    4 min read
  • How to Get the Data Type of a Columns in MariaDB
    When it comes to managing databases, understanding the types of data stored in each column is crucial. In MariaDB, this knowledge not only helps in organizing data efficiently but also enables more effective querying and analysis. In this article, we'll explore How to Get the Data Type of Columns in
    4 min read
  • How to Check Column Type in SQLite?
    SQLite is a lightweight and relational database management system. SQLite is used to develop embedded software for devices like televisions, cell phones, cameras, etc. SQLite is a serverless database system which means it does not require any server to process queries. In this article, we will how t
    3 min read
  • How to Get Column Names in MySQL?
    To get column names in MySQL use techniques such as the DESCRIBE statement, INFORMATION_SCHEMA.COLUMNS, and SHOW COLUMNS FROM commands. Here will cover these techniques, with explained examples, and help to get a better understanding on how to get column names in MySQL. MySQL Fetch Column Names from
    3 min read
  • Convert the data type of Pandas column to int
    In this article, we are going to see how to convert a Pandas column to int. Once a pandas.DataFrame is created using external data, systematically numeric columns are taken to as data type objects instead of int or float, creating numeric tasks not possible. We will pass any Python, Numpy, or Pandas
    2 min read
  • How to Delete Column in SQL
    In SQL, deleting a column from an existing table is a straightforward process, but it's important to understand the implications and the correct syntax involved. While there is no direct DELETE COLUMN command in SQL, we can achieve this by using the ALTER TABLE command combined with DROP COLUMN. In
    5 min read
  • How to Get the Datatype of Table Columns in MySQL?
    When working with MySQL databases, knowing the datatype of table columns is essential to maintain data integrity and avoid errors. This guide covers methods to check column datatypes, such as using SHOW COLUMNS and querying INFORMATION_SCHEMA.COLUMNS. Understanding column datatypes helps in designin
    4 min read
  • How to Check Column Types in PostgreSQL?
    In PostgreSQL, checking column types is an important aspect of understanding the structure and data stored in a database table. It helps database developers and administrators work effectively by providing a clear picture of the database schema. In this article, we will explore various methods to ch
    4 min read
  • How to Find the Maximum of Multiple Columns in SQL
    Finding the maximum value of multiple columns is one of the most common analytical tasks essential for making decisions and analyzing data. Using the MAX() function of SQL, users can find the maximum value in a single column. But to find the maximum value in multiple columns, users need to use other
    2 min read
  • How to get column names from SQLAlchemy?
    In this article, we will discuss how to get column names using SQLAlchemy in Python. SQLAlchemy is an open-source SQL toolkit and object-relational mapper for the Python programming language released under the MIT License. It gives full power and flexibility of SQL to an application. To follow along
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences