Create a database CREATE Database name/* DEFAULT CHARSET UTF8 COLLATE utf8_general_ci;*/
- Deleting a database DROP DATABASES database name;
Show Database list SHOW DATABASES;
- Show Table List SHOW TABLES;
Switch Database Use database name;
- Build Table CREATE TABLE ' table1 ' (' ID ' INT (3) NOT NULL auto_increment, ' user_name ' VARCHAR (+) ' NOT NULL, ' password ' CHAR (+) ' NOT NULL , PRIMARY KEY (' id ')) auto_increment=1 engine=myisam DEFAULT CHARSET UTF8 COLLATE utf8_general_ci;
- Delete a table DROP TABLE table1;
- Clear Table (The index data is cleared) TRUNCATE TABLE table1;
- Modify table structure
- Add primary key ALTER table ' table1 ' add& nbsp Primary key (field name);
- Remove the add from the primary key and replace it with a drop
- add unique key alter table ' table1 ' add unique key (field name);
- add normal key alter table ' table1 ' add index (field name);
- add field alter table ' table1 ' ADD ' field name ' int (3)/* (After ' field Name 2 ') after which field */;
- Modify field cannot be changed to field name alter table ' table1 ' MODIFY ' field name ' varchar (a) not NULL
- change field name alter table ' table1 ' CHANGE ' field name ' ' new field name ' varchar (() not NULL
- Delete field alter table ' table1 ' DROP ' ziduan1 ';
- modifying table Data
- Add: INSERT INTO ' table name ' (' Field name 1 ', ' Field 2 ' ...) values (' Value 1 ', ' Value 2 ' ...);
- Delete: Delete from ' table name ' where ' Field 1 ' > ' and/*or*/' Field 2 ' < ' 100 ';
- Change: Update ' table name ' Set ' field 1 ' = ' value 1 ', ' field 2 ' = ' value 2 ' .../*where condition */
- Check: Select ' Field 1 ', ' Field 2 ' ... from ' table name '/*where condition */
High-frequency SQL statement Summary