Common operations for MySQL databases

Source: Internet
Author: User

/*Create a table*/CREATE TABLEtb_test (IDint( One) unsigned not NULLAuto_increment COMMENT'self-increment primary key', namevarchar( -) not NULL DEFAULT "'COMMENT'name',user_id int( One) unsigned not NULL DEFAULT '0'COMMENT'User ID', Update_timeint( One) unsigned not NULL DEFAULT '0'COMMENT'Modification Time', Is_deltinyint(1) unsigned not NULL DEFAULT '0'COMMENT'whether to disable',PRIMARY KEY(ID),KEYUSER_IDX (Name,user_id) ) ENGINE=InnoDB auto_increment=1 DEFAULTCHARSET=UTF8 COMMENT='User Information';/*Adding a field to a table add*/ALTER TABLETb_testADDIs_urltinyint(1) not NULL DEFAULT 1COMMENT'whether it is a URL';/*Modify the type of a field MODIFY*/ALTER TABLETb_test MODIFY Is_urlint( One) not NULL DEFAULT 1COMMENT'whether it is a URL';/*to modify the name of a field, be sure to re-specify the field's type change*/ALTER TABLETb_test Change Is_url Is_web_urlint( One) not NULL DEFAULT 1COMMENT'whether it is a URL';/*Add a normal index*/ALTER TABLETb_testADD KEYis_del_x (Update_time,is_del);ALTER TABLETb_testADD INDEXidx_name_content (name);/*Delete a field*/ALTER TABLETb_testDROP COLUMNIs_web_url;/*Renaming a table*/RENAMETABLETb_test toTb_ceshi/*Add Data*/Insert  intoTb_test (' id ', ' name ', 'user_id`)Values(1,'ha ha haha',1001),(2,'John Doe',1002);/*Modifying Data*/UpdateTb_testSet' Name '=' ABCD 'whereId=5;/*Delete Data*/Delete  fromTb_testwhereId=5; 

Common operations for MySQL databases

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.