MySQL Modify table structure

Source: Internet
Author: User

Self-summary, there is any need to correct the supplementary place, please correct me, thank you!

Purpose: When the table structure needs to be modified in the project and it needs to be advertised to other colleagues, the efficient way to do this is to send the statement that modifies the table structure to other colleagues.

Operations on table fields: Add,drop,modify | Change.

add: Feature 1: New Add field (default Add New field after all fields) syntax 1:alter table+ Table name + add + new Field + new field type + whether new field can be empty +default ALTER TABLE student add classname varchar (() notNULL default‘‘; function 2: Place the new plus field at the front of all fields syntax: ALTER TABLE+ table name +add + new field + new field type + new field is empty + default value +First ALTER TABLE student add classname varchar (() notNULL default‘‘function 3: Break the current price again after a field syntax: ALTER TABLE+ table name +add + new field + new field type + new field is empty + default + after +the field name that already exists ALTER TABLE student add ClassnointNotNULLAfter age ; drop: syntax: ALTER TABLE+ Table name +drop +the field name that already exists ALTER TABLE student drop classno; Modify table Field properties: function 1 (Modify): Modify the type or default syntax for fields: ALTER TABLE+ Table name +modify + fields to modify + Modify field type +default ALTER TABLE student modify name varchar (() notNULL default‘‘; function 2 (change): Modify the name of the field syntax: ALTER TABLE+ table name +change + Old field + new Field + new type + null +default ALTER TABLE student change name room_id varchar (6) notNULL default' 0 ';

Basic information:

        1. The Modify Table Structure command is identified with an [ALTER] statement, for example [ALTER TABLE student] 2. Add,Modify, and delete command identifiers for Add, modify, drop, respectively.    3. View table structure statements for example [DESC student;]    4. View the build table statements such as [  Show create table student;] 5. Setting default values is not required, and if you do, the default value for MySQL is null 6. Not NULL is not required, and if you do, the default value for MySQL is yes   to default 0 is the same Of    

I also refer to other friends of the park blog,

Original source: http://www.cnblogs.com/qintangtao/archive/2012/11/17/2775209.html

MySQL Modify table structure

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.