- SQL Basics
- SQL Introduction
- SQL Syntax
- SQL Sample Database
- SQL SELECT
- SQL WHERE
- SQL ORDER BY
- SQL DISTINCT
- SQL LIMIT
- SQL FETCH
- SQL AND
- SQL OR
- SQL BETWEEN
- SQL IN
- SQL LIKE
- SQL IS NULL
- SQL Comparison Operators
- SQL Logical Operators
- SQL Alias
- SQL CASE
- Joins and Subqueries
- SQL INNER JOIN
- SQL LEFT JOIN
- SQL RIGHT JOIN
- SQL FULL OUTER JOIN
- SQL SELF JOIN
- SQL CROSS JOIN
- SQL Subquery
- SQL Correlated Subquery
- SQL UNION
- SQL INTERSECT
- SQL EXCEPT
- Aggregate Functions
- SQL AVG
- SQL COUNT
- SQL MAX
- SQL MIN
- SQL SUM
- SQL GROUP BY
- SQL HAVING
- SQL ROLLUP
- SQL CUBE
- SQL GROUPING SETS
- Database Management
- SQL CREATE DATABASE
- SQL ALTER DATABASE
- SQL DROP DATABASE
- SQL BACKUP DATABASE
- SQL SHOW DATABASES
- SQL SELECT DATABASE
- Table Management
- SQL CREATE TABLE
- SQL ALTER TABLE
- SQL ADD COLUMN
- SQL DROP COLUMN
- SQL DROP TABLE
- SQL TRUNCATE TABLE
- SQL SHOW TABLES
- SQL RENAME TABLE
- SQL Constraints
- SQL Primary Key
- SQL Foreign Key
- SQL UNIQUE Constraint
- SQL CHECK Constraint
- SQL NOT NULL Constraint
SQL ALTER DATABASE
The ALTER DATABASE
statement is used to modify an existing database's settings, such as changing its collation or character set.
Syntax of SQL ALTER DATABASE
ALTER DATABASE database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
- database_name: The name of the database to be modified.
- CHARACTER SET: Defines the new character set.
- COLLATE: Defines the new collation rule.
Key Features of SQL ALTER DATABASE
- Modifies database-level settings.
- Common changes include character set and collation.
- Requires appropriate privileges to alter a database.
Example of SQL ALTER DATABASE
ALTER DATABASE SchoolDB CHARACTER SET utf8 COLLATE utf8_general_ci;
Output:
The character set and collation of SchoolDB
are updated.
Checking Current Database Settings
To check the current character set and collation:
SELECT schema_name, default_character_set_name, default_collation_name
FROM information_schema.schemata
WHERE schema_name = 'SchoolDB';
Summary
ALTER DATABASE
is used to modify database settings.- Common modifications include character set and collation.
- Use
SELECT
frominformation_schema.schemata
to check the current settings.