SQL Data Types Reference 📝

beginner
18 min

SQL Data Types Reference 📝

Welcome to our deep dive into SQL Data Types! This tutorial is designed for beginners and intermediates, so let's get started!

Understanding SQL Data Types 🎯

SQL data types are used to store, retrieve, and manipulate data in a structured way. They help in ensuring the integrity and consistency of the data in a database.

Core SQL Data Types 📝

1. Integer Types 💡

  • INT: Signed integer, can hold numbers between -2147483648 and 2147483647
  • BIGINT: Larger signed integer, can hold numbers between -9223372036854775808 and 9223372036854775807

2. Floating Point Types 💡

  • FLOAT/REAL: Single precision floating point, can hold numbers with up to 7 digits of precision
  • DOUBLE PRECISION: Double precision floating point, can hold numbers with up to 15 digits of precision

3. Decimal Types 💡

  • DECIMAL/NUMERIC: Fixed precision decimal type, can hold numbers with a fixed number of digits before and after the decimal point

4. String Types 💡

  • CHAR: Fixed-length character string, stores strings of a specific length
  • VARCHAR: Variable-length character string, stores strings of any length up to a maximum limit
  • TEXT: Variable-length character string, stores large amounts of text

5. Date and Time Types 💡

  • DATE: Stores date values, in the format YYYY-MM-DD
  • TIME: Stores time values, in the format HH:MM:SS
  • DATETIME: Stores both date and time values

Working with SQL Data Types 🎯

Let's look at a practical example to better understand how to work with SQL data types:

sql
CREATE TABLE Employees ( EmployeeID INT, FirstName VARCHAR(50), LastName VARCHAR(50), BirthDate DATE, HireDate DATETIME, Salary DECIMAL(8,2) );

In this example, we have created a table named Employees with various SQL data types:

  • EmployeeID is an integer
  • FirstName and LastName are strings (VARCHAR)
  • BirthDate is a date
  • HireDate is a datetime
  • Salary is a decimal type

Now that we have our table, we can insert, update, and retrieve data from it using SQL statements.

Quiz 🎯

Quick Quiz
Question 1 of 1

What is the data type that stores both date and time values in SQL?

Happy learning! 📝💡🎯