##################################################################Author: Chen #_blogs:http:/ /www.cnblogs.com/chenyuebai/#################################################################
version:5.7.17
------------------------------------------------------------------------------------------------------------- -------------------------------1. Database operations Create a library:Create Databasesamp_dbcharacter SetGBK; Delete databases: drop database samp_db;
------------------------------------------------------------------------------------------------------------ --------------------------------2. Table Operations
Create a tableCreate TableStudents (IDint not NULL Primary Key, nameChar( A) not NULL, SexChar(4) not NULL, Ageint not NULL, TelChar( -) not NULL default '-')
Add the basic form of the column:Alter TableTable nameAddColumn list data type[After insertion position]; Example: Append column address at the end of the table:Alter TableStudentsAddAddressChar( -); Insert column birthday after the column named Age:Alter TableStudentsAddBirthday Date after-age, modifying the basic form of a column:Alter Tabletable name change column Name column new name new data type; example: Renaming a table Tel column to Telphone:Alter TableStudents Change Tel TelphoneChar( -)default"-"To change the data type of the Name column toChar( -):Alter TableStudents change name NameChar( -) not NULL; Delete the basic form of a column:Alter TableTable nameDropcolumn name; example: Delete the birthday column:Alter TableStudentsDropBirthday; Rename table basic form:Alter TableTable name rename new table name; example: Renaming the students table is workmates:Alter Tablestudents rename workmates; Delete the entire table basic form:Drop Tabletable name; example: Deleting a workmates table:Drop Tableworkmates; Delete the entire database basic form:Drop Databasedatabase name; example: Deleting a samp_db database:Drop Databasesamp_db;------------------------------------------------------------------------------------------------------------- -------------------------------3. Data ManipulationInsert intoStudentsValues(00001,'Chen','male', -,"')INSERT intoTestdb.students (Id,name,sex,age)VALUES(00003,'Li Lin','male', A)Deletestatement is used to delete data from a table, using the following basic usage:Delete fromTable namewheredelete condition;Updatestatements can be used to modify data in a table, using the following basic form:UpdateTable nameSetColumn Name=New valuewhereupdate conditions;Select * fromTableNamewhere ...
MySQL basic syntax