Examples of MariaDB Alter Database
Example 1: Changing Character Set and Collation:
This is an example of how to change the character set and collation of a database which is already installed. We will have to choose the appropriate character set and collation based on our data needs.
Query:
ALTER DATABASE Minal CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Now we can check whether the character set and collation is changed or not:
Query:
SELECT @@character_set_database, @@collation_database;
Output:
Explanation: As we can see in image that the above character set and collation was different of database named as ‘Minal‘ and now it is changed.
MariaDB Alter Database
MariaDB is an open-source relational database management system. In comparison to MySQL, MariaDB possesses several similar features, including ACID compliance, support for a wide range of storage engines, and availability of different data types. As our data needs develop, the demand to modify our databases will become necessary. In MariaDB, the ALTER DATABASE statement comes out as an effective command for altering existing databases. This article will delve into the different facets of modifying databases in MariaDB, including syntax, frequent contexts, and optimal strategies to ensure smooth database transmutation.
ALTER DATABASE Statement in MariaDB
The ALTER DATABASE command in MariaDB gives users the ability to make changes to an existing database. This helpful command serves various changes, including changing database parameters and capabilities. Moreover, let’s go deeper into the syntax and look at some typical cases.
Syntax:
ALTER DATABASE database_name [CHARACTER SET [=] charset_name] [COLLATE [=] collation_name]
Explanation:
- ALTER DATABASE: This is the main statement that indicates that we want to modify an existing database.
- database_name: Put the name of the database we want to change here. This is the database whose attributes we are changing.
- [CHARACTER SET [=] charset_name]: This part is optional and can be used in the case when we want to change the default character set for the given database. As seen in the square brackets it is optional and we can decide to include this part or eliminate it. If included, we would replace charset_name with the desired character set. The = sign is also optional, meaning we can use CHARACTER SET charset_name without the =.
- [COLLATE [=] collation_name]: Similar to the character set, this part is also optional. It allows we to change the default collation for the specified database. If included, replace collation_name with the desired collation. The = sign is, again, optional.
Character Set and Collation are concepts in database management that define how data is stored and compared in terms of characters, particularly text data.
Contact Us