Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Friday, 16 February 2024

Different Data types in MARIADB

In MariaDB, there are various data types that you can use to define columns in your database tables. Here is a list of some commonly used data types in MariaDB along with examples:

1. Integer Types:

   - INT: Integer data type (4 bytes).

   CREATE TABLE ExampleTable (

       ID INT

   );

   - BIGINT: Big integer data type (8 bytes).

   CREATE TABLE ExampleTable (

       ID BIGINT

   );

2. Numeric Types:

   - DECIMAL: Fixed precision and scale numeric data type.

   CREATE TABLE ExampleTable (

       Price DECIMAL(10, 2)

   );

   - FLOAT: Floating-point number data type.

   CREATE TABLE ExampleTable (

       Price FLOAT

   );

3. Character Types:

   - VARCHAR: Variable-length character data type.

   CREATE TABLE ExampleTable (

       Name VARCHAR(50)

   );

   - CHAR: Fixed-length character data type.

   CREATE TABLE ExampleTable (

       Initial CHAR(1)

   );

4. Text Types:

   - TEXT: Variable-length character data type for large text values.

   CREATE TABLE ExampleTable (

       Description TEXT

   );

5. Date and Time Types:

   - DATE: Date data type.

   CREATE TABLE ExampleTable (

       BirthDate DATE

   );

   - DATETIME: Date and time data type.

   CREATE TABLE ExampleTable (

       LastUpdate DATETIME

   );

6. Boolean Type:

   - BOOLEAN or BOOL: Boolean data type.

   CREATE TABLE ExampleTable (

       IsActive BOOLEAN

   );

7. Binary Types:

   - BINARY: Fixed-length binary data type.

   CREATE TABLE ExampleTable (

       BinaryData BINARY(10)

   );

   - VARBINARY: Variable-length binary data type.

   CREATE TABLE ExampleTable (

       ImageData VARBINARY(255)

   );

8. JSON Type:

   - JSON: Stores JSON data.

   CREATE TABLE ExampleTable (

       UserData JSON

   );

9. UUID Type:

   - UUID: Stores universally unique identifier data.

   CREATE TABLE ExampleTable (

       GUIDColumn UUID

   );

These are just some of the data types available in MariaDB. Depending on your requirements, you may choose different data types to define columns in your database tables.

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.