MySQL dynamic Add a deletion column field command

Source: Internet
Author: User

How does MySQL dynamically add a pruning column field, as sql:

Dynamically add column fields:

ALERT TABLE table1 Add transactor varchar (a) not Null;

To delete a column field dynamically:

ALERT TABLE tablename drop column field_id;

To modify a column field dynamically:

ALERT TABLE table_name Change old_field_name new_field_name field_type;

Dynamically modifying table Structures

ALERT TABLE table_name MODIFY field_name Field_type

Add after creating table: ALTER TABLE tablename add ID int auto_increment PRIMARY key

Set the self-add field initial value: ALTER TABLE tablename auto_increment =x;

Set PRIMARY key: ALTER TABLE TableName add primary key (Field_name);

Creating a composite primary key: CREATE TABLE tablename (
                                    Studentno int,
                                    CourseID int,
                                    score int,
                                    primary KEY (Studentno,courseid);


Set composite PRIMARY key: ALTER TABLE TableName add PRIMARY key (column 1, column 2, column 3);

Renaming table: ALTER TABLE table_old_name rename Table_new_name;

Change the type of field: ALTER TABLE tablename modify Field_name Field_type;

Rename field: ALTER TABLE tablename change Old_field_name new_field_name new_field_type;

Delete field: ALTER TABLE tablename drop column field_name;

Add a new field: ALTER TABLE tablename add New_field_name field_type;

New field with default value of 0, Non-empty: ALTER TABLE tablename add New_field_name field_type NOT null default ' 0 ';

New field with default value of 0, Non-null, Tabelname, PRIMARY key: ALTER TABLE add New_field_name field_type default 0 NOT NULL auto_increment, add primary Key (New_field_name);

To modify a field type:

ALTER TABLE tablename change Filed_name filed_name new_type;

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.