MySQL adds a column to a table, deletes a column, modifies the column name

Source: Internet
Author: User
Tags aliases

If you want to add a column to a table that has already been built, you can use the following code:Alter TableTable nameAdd columnColumn Namevarchar( -) not NULLThis statement adds a column to an existing table in the last column of the table. If we want to add a column in the specified, you can use:Alter TableTable nameAdd columnColumn Namevarchar( -) not NULLafter User1; note that the above command means adding addr columns to the User1 column. If you want to add to the first column, you can use:Alter TableTable nameAdd columnColumn Namevarchar( -) not NULLFirst ; Change the column name def to unit in table Yusheng Alter Tableweb1.new_table Change def unitCharDelete columns in table Yusheng, column name DefAlter TableYushengDrop columndef;


Copying table TablesCreate Tablenew table name (SelectId,name, Number, Numberid fromthe name of the table to copy); View the table's various data types describe ' student ' view the table's saved dataSelect *  fromTable Name (SelectId,name, Number, Numberid fromtable name) Add DataInsert  intoTable name (Id,name, Number, Numberid)Values(1,'Logic', -,1),(2,'HTML', the,1),(3,'Java OOP', the,1); Delete DataDelete  fromTable namewherecondition; Modify the dataUpdateTable nameSetNumberid=2 whereConditional Descending orderSelectId,name, Number, Numberid fromTable nameOrder  byIddesc; add an aliasSelectID (column name)'aliases', (column name) as 'aliases'  fromTable name;

MySQL adds a column to a table, deletes a column, modifies the column name

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.