![](https://i0.wp.com/media.dev.to/cdn-cgi/image/width=1000,height=500,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjwhylvzomx4azpkgrqh0.png?w=1200&ssl=1)
Hello Everyone,
This is my Day 3 talking about SQL haha if you haven’t read my other blogs you can view it in my profile then please read it also and dont forget to like it.
Now let’s go back to our topic for today which is SQL DATA TYPES if you saw my previous post we discuss about queries and some theory about SQL now we’re going to focus on sql data types. so first let’s define what is data types.
SQL data types define the type of data that can be stored in the database table’s columns. Each column have a data type, which determines the kind of values that can be inserted into that column. It’s like were telling each column what only data we are accepting or to store in it.
Now that we have a glimpse of what is sql data types is now let’s discuss the different types of data types.
NUMERIC TYPES
- INTEGER/INT – Represents integer number whole numbers only no decimal points. there are range that integer are accepting it’s like -2,147,483,648 to 2,147,483,647 number only. if you want to store big numbers you need to use BIGINT. if small numbers SMALLINT.
- DECIMAL(n, p) – Represents fixed-points numbers with exact precision so if you’re data have decimal you need to use decimal types to get also the decimal points of the data. if you use integer type the decimal point will not show.
CHARACTER STRING TYPES
- CHAR: Fixed-length character strings like if you declare your column type is char(5) it will only limit it accepting 5 characters only. CHAR can be useful when you know that the length of the data will always be the same, as it can help save storage space and ensure consistent data length.
- VARCHAR: Variable-length character strings. this type is good to store texts the maximum length of this varchar is 255 only.
- TEXT: Variable-length character strings with larger maximum length. this text is same in varchar but the text type can occupy more length than varchar.
DATE AND TIME TYPES
DATE: Represents date values in the format ‘YYYY-MM-DD’. Specifically for date only.
TIME: Represents time values in the format ‘HH:MM:SS’. Opposite of the date.
DATETIME/TIMESTAMP: Represents date and time values in the format ‘YYYY-MM-DD HH:MM:SS’. It’s like combination of the two above.
Boolean Type:
- BOOLEAN/BOOL: Represents boolean values (true/false).
There are some types commonly found when viewing a database table schema. If you want to dive deeper into the data types, you can find more information in the documentation of your chosen database server, whether it’s MySQL or PostgreSQL.
If you find this blog useful please drop a like and if you have something like concern or feedback you can free to comment on this post and we can discuss it. Thank you so much 🙂
MARKME