High-frequency SQL statement Summary

Source: Internet
Author: User

  1. Create a database CREATE Database name/* DEFAULT CHARSET UTF8 COLLATE utf8_general_ci;*/

  2. Deleting a database DROP DATABASES database name;
  3. Show Database list SHOW DATABASES;

  4. Show Table List SHOW TABLES;
  5. Switch Database Use database name;

  6. 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;
  7. Delete a table DROP TABLE table1;
  8. Clear Table (The index data is cleared) TRUNCATE TABLE table1;
  9. Modify table structure
    1. Add primary key ALTER table  ' table1 '  add& nbsp Primary key (field name);
    2. Remove the add from the primary key and replace it with a drop
    3. add unique key alter table  ' table1 '  add unique key (field name);
    4. add normal key alter table  ' table1 '  add index (field name);
    5. add field alter table  ' table1 '  ADD  ' field name '  int (3)/* (After ' field Name 2 ') after which field */;
    6. Modify field cannot be changed to field name alter table  ' table1 '  MODIFY  ' field name '  varchar (a)  not NULL
    7. change field name alter table  ' table1 '  CHANGE  ' field name '   ' new field name '  varchar (()  not NULL
    8. Delete field alter table  ' table1 '  DROP  ' ziduan1 ';
  10. modifying table Data
    1. Add: INSERT INTO ' table name ' (' Field name 1 ', ' Field 2 ' ...) values (' Value 1 ', ' Value 2 ' ...);
    2. Delete: Delete from ' table name ' where ' Field 1 ' > ' and/*or*/' Field 2 ' < ' 100 ';
    3. Change: Update ' table name ' Set ' field 1 ' = ' value 1 ', ' field 2 ' = ' value 2 ' .../*where condition */
    4. Check: Select ' Field 1 ', ' Field 2 ' ... from ' table name '/*where condition */

High-frequency SQL statement Summary

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.