MySQL Build table index

Source: Internet
Author: User
Tags add time

Build table:

CREATE TABLE ' sj_projects ' (
' id ' int (one) not NULL auto_increment,
' title ' varchar (255) Not NULL DEFAULT ' COMMENT ' project name ',
' platform_id ' int (one) not NULL DEFAULT ' 0 ' COMMENT ' platform ID ',
' unique_id ' varchar (255) Not NULL DEFAULT ' COMMENT ' project and data unique ID ',
' Repayway ' varchar (255) Not NULL DEFAULT ' COMMENT ' repayment method ',
' Profit ' decimal (5,2) not NULL DEFAULT ' 0.00 ' COMMENT ' annual yield ',
' Speed ' decimal (5,2) is not NULL DEFAULT ' 0.00 ' COMMENT ' Progress ',
' Frequency ' int (one) not NULL DEFAULT ' 0 ' COMMENT ' investment number ',
' Amount ' decimal (20,2) not NULL DEFAULT ' 0.00 ' COMMENT ' Financing amount ',
' Res_amount ' decimal (20,2) not NULL DEFAULT ' 0.00 ' COMMENT ' remaining available amount ',
' Invtime ' timestamp not NULL DEFAULT ' 0000-00-00 00:00:00 ' COMMENT ' project investment start time ',
' Endtime ' timestamp not NULL DEFAULT ' 0000-00-00 00:00:00 ' COMMENT ' project investment End Time ',
' Turntime ' timestamp not NULL DEFAULT ' 0000-00-00 00:00:00 ' COMMENT ' Project repayment time (customer payment time) ',
' Term ' varchar (a) Not NULL DEFAULT ' ' COMMENT ',
' Type ' int (one) not NULL DEFAULT ' 0 ',
' Pageurl ' text COMMENT ' note case Pageurl ',
' Insert_time ' timestamp not NULL DEFAULT current_timestamp COMMENT ' Add Time ',
' orderby_id ' int (one) not NULL DEFAULT ' 1 ' COMMENT ' sort ',
' Status ' tinyint (1) Not NULL DEFAULT ' 1 ' COMMENT ' state 0 is off, 1 is open ',
PRIMARY KEY (' id '),
KEY ' unique_id ' (' unique_id ') USING BTREE

) Engine=innodb auto_increment=2383 DEFAULT Charset=utf8 row_format=dynamic comment= ' Project table ';

If the unique index: unique KEY ' unique_id ' (' unique_id ') USING BTREE

You can also do this directly: (Unique index)

unique_id  VARCHAR (255) Unique not NULL DEFAULT ' COMMENT ' project and data unique ID ',

Inquire:

Show index from Sj_projects; --Query all indexes of sj_projects

SHOW CREATE TABLE Sj_projects\g

To add an index:

ALTER TABLE ' sj_projects ' ADD UNIQUE ' unique_id ' (' unique_id '); --Unique index

ALTER TABLE ' sj_projects ' ADD INDEX ' unique_id ' (' unique_id '); --General Index

ALTER TABLE ' sj_projects ' ADD INDEX ' uniqueId ' (' unique_id '); --Normal index can modify the name

To delete an index:

ALTER TABLE ' sj_projects ' DROP INDEX ' unique_id ';

To delete the self-Increment ID index:

The automatic growth of the ID key needs to be canceled first:

ALTER TABLE ' sj_projects ' MODIFY ' id ' int (ten) not NULL COMMENT ' id ';

Execute again: ALTER TABLE ' sj_projects ' DROP PRIMARY KEY;

MySQL Build table index

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.