Database common operations Records: New Add column, rename column, modify column length and type, delete column, rename table name, etc.

Source: Internet
Author: User

1. Add a new column to the existing table in the database

Statement:altertable    name  add   column name   type    Example:alter  MyUser  ADD  Userdesc  VARCHAR(+);

2. Name the rename in the existing tables in the database

Statement:altertablecolumn to    new columns name;   Example:altertablecolumn to Pk_group;

3. Modify the length and type of columns in the tables that are already in the database

Statement:alter table   name modify  column name  type (length);   Example:altertable myuser  Modify  Varchar(+);        Alter Table SMALLINT;

4. Delete a column for existing tables in the database

Statement:altertable  drop  column name, example:altertable  Dropcolumn Venterplan;

5. Renaming existing tables in the database

 table name to    new show;    Table  to user;
6. Add more columns for existing tables in the database

Statement:altertableadd (column name type, column name type,...) ; Example: Alter Table Add VARCHAR (255varchar(+));

7. Copy table data for existing tables in the database

Statement:Insert into Aa_files (id,name,diskSelect id,name,disk, Hash,size, Date,'yy' from Yy_files;

Database common operations Records: New Add column, rename column, modify column length and type, delete column, rename table name, etc.

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.