The SQL keyword that indicates modifying a database object is: ALTER. In the database, you can use the "ALTER TABLE" statement to change the structure of the original table, and add, delete, or modify columns in the existing table.
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
The SQL keyword indicating modifying a database object is: alte.
SQL ALTER DATABASE statement
In MySQL, you can use ALTER DATABASE to modify Relevant parameters of the database that has been created or exists. The syntax format for modifying the database is:
ALTER DATABASE [数据库名] { [ DEFAULT ] CHARACTER SET <字符集名> | [ DEFAULT ] COLLATE <校对规则名>}
The syntax description is as follows:
ALTER DATABASE is used to change the global characteristics of the database.
Using ALTER DATABASE requires database ALTER permissions.
The database name can be ignored, and the statement corresponds to the default database.
The CHARACTER SET clause is used to change the default database character set.
Example:
View the execution results of the definition statement of the test_db database
mysql> SHOW CREATE DATABASE test_db; +----------+--------------------------------------------------------+ | Database | Create Database | +----------+--------------------------------------------------------+ | test_db | CREATE DATABASE `test_db` /*!40100 DEFAULT CHARACTER SET utf8 */| +----------+--------------------------------------------------------+ 1 row in set (0.05 sec)
Use the command line tool to modify the specified character set of the database test_db to gb2312 , the default proofreading rule is modified to gb2312_unicode_ci
mysql> ALTER DATABASE test_db -> DEFAULT CHARACTER SET gb2312 -> DEFAULT COLLATE gb2312_chinese_ci; mysql> SHOW CREATE DATABASE test_db; +----------+--------------------------------------------------------+ | Database | ALTER Database | +----------+--------------------------------------------------------+ | test_db | ALTER DATABASE `test_db` /*!40100 DEFAULT CHARACTER SET gb2312 */| +----------+--------------------------------------------------------+ 1 row in set (0.00 sec)
(Recommended tutorial: mysql video tutorial)
SQL ALTER TABLE statement
SQL ALTER TABLE
statement is used to add, delete, or modify columns in an existing table. Use the ALTER TABLE
statement to change the structure of the original table, such as adding or deleting columns, changing the original column type, renaming columns or tables, etc.
The syntax format is as follows:
ALTER TABLE <表名> [修改选项]
The syntax format for modifying options is as follows:
{ ADD COLUMN <列名> <类型> | CHANGE COLUMN <旧列名> <新列名> <新列类型> | ALTER COLUMN <列名> { SET DEFAULT <默认值> | DROP DEFAULT } | MODIFY COLUMN <列名> <类型> | DROP COLUMN <列名> | RENAME TO <新表名> | CHARACTER SET <字符集名> | COLLATE <校对规则名> }
Modify table name
MySQL via ALTER TABLE statement is used to modify the table name. The syntax rules are as follows:
ALTER TABLE <旧表名> RENAME [TO] <新表名>;
Among them, TO is an optional parameter, and whether it is used or not does not affect the result.
Modify the table character set
MySQL uses the ALTER TABLE statement to modify the table character set. The syntax rules are as follows:
ALTER TABLE 表名 [DEFAULT] CHARACTER SET <字符集名> [DEFAULT] COLLATE <校对规则名>;
Among them, DEFAULT is Optional parameters, whether used or not does not affect the results.
Modify field names
The syntax rules for modifying table field names in MySQL are as follows:
ALTER TABLE <表名> CHANGE <旧字段名> <新字段名> <新数据类型>;
Among them:
-
Old field name: refers to the field name before modification;
New field name: refers to the modified field name;
New Data type: refers to the modified data type. If you do not need to modify the data type of the field, you can set the new data type to be the same as the original one, but the data type cannot be empty.
Modify field data type
Modifying the data type of a field is to convert the data type of the field into another data type. The syntax rules for modifying field data types in MySQL are as follows:
ALTER TABLE <表名> MODIFY <字段名> <数据类型>
Among them:
Table name: refers to the name of the table where the field whose data type is to be modified is located;
Field name: refers to the field that needs to be modified;
Data type: refers to the new data type of the modified field.
Delete a field
Deleting a field is to remove a field in the data table from the table. The syntax format is as follows:
ALTER TABLE <表名> DROP <字段名>;
Among them, "field name" refers to the name of the field that needs to be deleted from the table.
Add fields
1. Add fields at the end
A complete field includes field name, data type and constraints. The syntax format for adding fields in MySQL is as follows:
ALTER TABLE <表名> ADD <新字段名><数据类型>[约束条件];
The syntax format is explained as follows:
-
is the name of the data table;
is the name of the field to be added; is the field that can store data Data type;
[Constraints] is optional and is used to constrain the added fields.
This syntax format adds a new field at the last position of the table (after the last column) by default.
2. Add a field at the beginning
MySQL adds a new field at the last position of the table by default. If you want to add a new field at the beginning (in front of the first column), you can use the FIRST key word, the syntax format is as follows:
ALTER TABLE <表名> ADD <新字段名> <数据类型> [约束条件] FIRST;
FIRST keyword is generally placed at the end of the statement.
3. Add fields in the middle position
In addition to allowing fields to be added at the beginning and end of the table, MySQL also allows fields to be added in the middle position (after the specified field). At this time You need to use the AFTER keyword, the syntax format is as follows:
ALTER TABLE <表名> ADD <新字段名> <数据类型> [约束条件] AFTER <已经存在的字段名>;
The function of AFTER is to add a new field after an existing field.
Note that you can only add a new field after an existing field, but not in front of it.
For more knowledge about computer programming, please visit: Programming Video! !
The above is the detailed content of What is the SQL keyword that indicates modifying a database object?. For more information, please follow other related articles on the PHP Chinese website!

本篇文章给大家带来了关于SQL的相关知识,其中主要介绍了SQL Server使用CROSS APPLY与OUTER APPLY实现连接查询的方法,文中通过示例代码介绍的非常详细,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于SQL server的相关知识,其中主要介绍了SQL SERVER没有自带的解析json函数,需要自建一个函数(表值函数),下面介绍关于SQL Server解析/操作Json格式字段数据的相关资料,希望对大家有帮助。

如何优化sql中的orderBy语句?下面本篇文章给大家介绍一下优化sql中orderBy语句的方法,具有很好的参考价值,希望对大家有所帮助。

monacoeditor创建//创建和设置值if(!this.monacoEditor){this.monacoEditor=monaco.editor.create(this._node,{value:value||code,language:language,...options});this.monacoEditor.onDidChangeModelContent(e=>{constvalue=this.monacoEditor.getValue();//使value和其值保持一致i

本篇文章给大家带来了关于SQL server的相关知识,开窗函数也叫分析函数有两类,一类是聚合开窗函数,一类是排序开窗函数,下面这篇文章主要给大家介绍了关于SQL中开窗函数的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下。

0x01前言概述小编又在MySQL中发现了一个Double型数据溢出。当我们拿到MySQL里的函数时,小编比较感兴趣的是其中的数学函数,它们也应该包含一些数据类型来保存数值。所以小编就跑去测试看哪些函数会出现溢出错误。然后小编发现,当传递一个大于709的值时,函数exp()就会引起一个溢出错误。mysql>selectexp(709);+-----------------------+|exp(709)|+-----------------------+|8.218407461554972

当某些sql因为不知名原因堵塞时,为了不影响后台服务运行,想要给sql增加执行时间限制,超时后就抛异常,保证后台线程不会因为sql堵塞而堵塞。一、yml全局配置单数据源可以,多数据源时会失效二、java配置类配置成功抛出超时异常。importcom.alibaba.druid.pool.DruidDataSource;importcom.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;importorg.apache.

monacoeditor创建//创建和设置值if(!this.monacoEditor){this.monacoEditor=monaco.editor.create(this._node,{value:value||code,language:language,...options});this.monacoEditor.onDidChangeModelContent(e=>{constvalue=this.monacoEditor.getValue();//使value和其值保持一致i


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use
