SQL statement that adds a new column to a table after a column in MySQL

Source: Internet
Author: User

About MySQL

MySQL is an open source small relational database management system, the developer of the Swedish MySQL AB company. MySQL is widely used in small and medium-sized websites on the internet. Because of its small size, fast speed, low total cost of ownership, especially the open source, many small and medium-sized web sites in order to reduce the total cost of ownership of the site chose MySQL as the site database.

Mysql ALTER table verbose syntax

ALTER TABLE is used to change the structure of an existing table. For example, you can add or subtract columns, create or cancel an index, change the type of an existing column, or rename a column or table. You can also change the table's commentary and table type. www.169it.com

The ALTER table detailed syntax is as follows:

ALTER [IGNORE] TABLE tbl_name

Alter_specification [, Alter_specification] ...

Alter_specification:

ADD [COLUMN] column_definition [First | After Col_name]

| ADD [COLUMN] (column_definition,...)

| ADD INDEX [index_name] [Index_type] (Index_col_name,...)

| ADD [CONSTRAINT [symbol]]

PRIMARY KEY [Index_type] (Index_col_name,...)

| ADD [CONSTRAINT [symbol]]

UNIQUE [index_name] [Index_type] (Index_col_name,...)

| ADD [fulltext| SPATIAL] [index_name] (Index_col_name,...)

| ADD [CONSTRAINT [symbol]]

FOREIGN KEY [index_name] (Index_col_name,...)

[Reference_definition]

| ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}

| Change [COLUMN] Old_col_name column_definition

[first| After Col_name]

| MODIFY [COLUMN] column_definition [First | After Col_name]

| DROP [COLUMN] Col_name

| DROP PRIMARY KEY

| DROP INDEX index_name

| DROP FOREIGN KEY Fk_symbol

| DISABLE KEYS

| ENABLE KEYS

| RENAME [to] New_tbl_name

| ORDER by Col_name

| CONVERT to CHARACTER SET charset_name [COLLATE collation_name]

| [DEFAULT] CHARACTER SET charset_name [COLLATE collation_name]

| DISCARD tablespace

| IMPORT tablespace

| Table_options

| Partition_options

| ADD PARTITION partition_definition

| DROP PARTITION Partition_names

| COALESCE PARTITION Number

| REORGANIZE PARTITION partition_names into (partition_definitions)

| ANALYZE PARTITION Partition_names

| CHECK PARTITION Partition_names

| OPTIMIZE PARTITION Partition_names

| REBUILD PARTITION Partition_names

| REPAIR PARTITION Partition_names

SQL statement format for adding new columns to a table after a column in MySQL

ALTER table ' database name '. ' Table name ' ADD COLUMN ' ProcID ' VARCHAR (6) DEFAULT ' after ' ppidchanged ';

In MySQL, if the table name, database name, column name, you add, modify, update, you need to use the ESC keyboard accent, can be added, the corresponding column name or update changes.

MySQL a SQL statement that adds a new column to a table after a column is listed below:

The statement that adds the title column after the ID column in the Book table is as follows:

ALTER TABLE book add title varchar (1024x768) NOT NULL default "after ID;


This article is from:MySQL SQL statement that adds a new column to a table after a column

SQL statement that adds a new column to a table after a column in MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.