JIYIK CN >

Current Location:Home > Learning > DATABASE > MySQL >

unsigned in MySQL

Author:JIYIK Last Updated:2025/04/09 Views:

This tutorial aims to understand unsigned in MySQL.


unsignedUsing keywords in MySQL

Businesses and organizations have to assign data type as unsigned for certain columns. However, it is important to understand when and where to use this data type before using it.

While we know intthat can be used to provide any value in the range from -2147483648 to 2147483647, the unsigned data type works slightly differently.

It cannot support negative values. Also, its range increases from 0 to 4294967295.

Therefore, it is clear that there are two specific instances where you may choose to use unsigned data types.

Now that we know when to use this data type, let’s understand how this data type works and visualize it in a table.

However, before we get started, we create three dummy datasets to work with. Here, we create a table student_details_dummyand a few rows.

-- create the table student_details
CREATE TABLE student_details_dummy(
  stu_id int unsigned,
  stu_firstName varchar(255) DEFAULT NULL,
  stu_lastName varchar(255) DEFAULT NULL,
  primary key(stu_id)
);
-- insert rows to the table student_details_dummy
INSERT INTO student_details_dummy(stu_id,stu_firstName,stu_lastName)
 VALUES(1,"Preet","Sanghavi"),
 (2,"Rich","John"),
 (3,"Veron","Brow"),
 (4,"Geo","Jos"),
 (5,"Hash","Shah"),
 (6,"Sachin","Parker"),
 (7,"David","Miller");

As we can see, we stu_idset as student_detailsthe primary key of the table . It will ensure that the values ​​in this column cannot be duplicated or NULL.

Furthermore, we stu_idset the data type of the column to unsigned. The above query creates a table containing the first and last names of the students.

To see the entries in the data, we use the following code.

SELECT * FROM student_details_dummy;

The above code will give the following output.

stu_id	stu_firstName	stu_lastName
1	      Preet	        Sanghavi
2	      Rich	        John
3	      Veron	        Brow
4	      Geo	        Jos
5	      Hash	        Shah
6	      Sachin	    Parker
7	      David	        Miller

DESCRIBE TABLENow let us try to visualize the details of this table using statement in MySQL .

DESCRIBEThe statement helps us visualize the table so that we can drill down into each field of the table.

It also shows us any keys assigned to any columns, the data type assigned to each column, and any other extra information related to the table. This statement can be illustrated with the help of the following query.

DESCRIBE name_of_the_table;

In our case, we need to write the following query to check the data type associated with each column in the table.

DESCRIBE student_details_dummy;

This query will fetch us the following output.

Field				Type			Null	Key		Default		Extra
stu_id				int unsigned	NO		PRI
stu_firstName		varchar(255)	YES
stu_lastName		varchar(255)	YES

Hence, with the help of unsigned-unsigned keyword and DESCRIBE-unsigned statement, we can effectively assign and visualize unsigned data type from a table in MySQL.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

If ELSE in MySQL

Publish Date:2025/04/11 Views:85 Category:MySQL

In this tutorial, we aim to explore how to use IF ELSE the statement in MySQL. One of the key roles of a data analyst is to gather insights from the data and produce meaningful results. It can be done with the help of several data filtering

DATETIME vs. TIMESTAMP in MySQL

Publish Date:2025/04/11 Views:117 Category:MySQL

DATETIME and TIMESTAMP are two different data types that can be used to store values ​​that must contain both a date and a time portion. In this article, we will understand how it is stored in the database and the memory required for ea

Execute multiple joins in one query in MYSQL

Publish Date:2025/04/11 Views:94 Category:MySQL

Have you ever wondered how to include multiple joins in one query in MySQL? You have come to the right place. Remember that joins allow us to access information from other tables. This information is included separately to avoid redundancy.

Joining 3 tables in MySQL

Publish Date:2025/04/11 Views:187 Category:MySQL

In this tutorial, we will learn how to join three tables in MySQL. Businesses and organizations may have to visualize three tables simultaneously based on certain matching columns common to all three tables. This operation is allowed in MyS

Use of UPDATE JOIN in MySQL

Publish Date:2025/04/11 Views:85 Category:MySQL

This tutorial will explain how to use the statement in MySQL database UPDATE JOIN . We generally use joins to iterate over the rows in a particular table which may or may not have similar rows in other tables. We can UPDATE use JOIN the cla

How to use the Row_Number() function in MySQL

Publish Date:2025/04/11 Views:142 Category:MySQL

In this tutorial, we will explain how to use the VALUES function in MySQL ROW_NUMBER() . This is a sorting method that assigns consecutive numbers within a partition starting from 1. It is important to note that no two rows within a partiti

Multiple primary keys in MySQL

Publish Date:2025/04/11 Views:66 Category:MySQL

In this tutorial, our goal is to explore the concept of multiple primary keys for a table in MySQL. Many times, businesses and organizations have to assign certain columns as primary keys. This primary key has multiple uses and reasons to b

Displaying foreign keys in MySQL

Publish Date:2025/04/11 Views:55 Category:MySQL

In this tutorial, we aim to explore how to display foreign keys for tables and columns in MySQL. The type of key that references a primary key, also known as the primary key of another table, is called a foreign key. Understanding the forei

Select first N rows in MySQL

Publish Date:2025/04/11 Views:85 Category:MySQL

Sometimes, you have to select first N rows of MySQL database according to your project requirements. n The value of varies according to the requirement; it can be TOP 1 row or TOP 30 rows. We will learn how to select top N rows using the cl

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial