My SQL with 003 data table base operation syntax

Source: Internet
Author: User

Data Sheet
    1. View Data Sheet
    2. Modify Table Name
    3. Modify field names
    4. modifying field data types
    5. Add Delete-field
    6. Constraint (primary foreign key default check)

To view the table structure:

    • Syntax: Desribe (description) table_name;

      DESC table_name;

    • Syntax: show CREATE TABLE table_name;

Show CREATE TABLE table_name \g;

Modify Table Name:

    • Syntax: ALTER TABLE table_name rename to table_new;

Modify Field Name:

    • Syntax: ALTER TABLE table_name change table_filed table_newfiled new_type;

modifying field data types

To modify the field data type:

    • Grammar : ALTER TABLE table_name modify Field_table New_type (ten);

Add Delete-field:

    • Syntax: ALTER TABLE table_name add new_table_name new_type;
    • Syntax: ALTER TABLE TABLE_NAME DROP TABLE_NAME;

Constraints:

PRIMARY KEY constraint FOREIGN KEY constraints CHECK constraints Default Constraints
PrimaryKey Foreigkey Check Default

PRIMARY KEY constraint:

    • Syntax: ALTER TABLE users ADD constraint pk_users_users_qq PRIMARY KEY (USERS_QQ);

FOREIGN KEY constraints:

    • Syntax: ALTER TABLE scoers ADD constraint fk_scoers_users_qq FOREIGN KEY (USERS_QQFK) REFERENCES users (UESRS_QQ);

CHECK constraints:

    • Syntax:ALTER table table_name add constraint ck_ (games) Table name _ (scoers) field CHECK (scoers>0);

Default value:

    • Syntax: Alter TABLE TABLE_NAME alter user_sex SET DEFAULT ' male ';

2017-07-02

My SQL with 003 data table base operation syntax

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.