MySQL database command-line operations-operations on tables and fields

Source: Internet
Author: User

First, the operation of the table

1. View all Tables

Show tables;

2. Create a table

CREATE TABLE table name (field 1 type 1 constraint 1, field 2 type 2 constraint 2);

3, modify the name of the table

Rename table name to the  new name;

4. Delete a table

drop table name;

Second, the operation of the field

1. Query fields (table structure)

Desc  table name;

2. Add Field

ALTER TABLE name add field name type constraint;

3. Modify Fields

ALTER TABLE name change  field name new field name type constraint

4. Delete fields

ALTER TABLE table name drop field name

5. Delete primary key

You need to change the primary key ID to a normal ID to not grow automatically, and then delete the primary key

ALTER TABLE students change ID idint;
ALTER TABLE students drop PRIMARY key;
ALTER TABLE students change ID idint auto_increment primary key notnull;

MySQL database command-line operations-operations on tables and fields

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.