/*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