sql statement operation

MySQL syntax is capitalized! Statement must end with a semicolon;

In SQL statements - English double bar + space denotes a comment

1. Check the database:

  $ show databases;

2. Create a database

 the Create databasse database name;

  Advanced Applications

    Create a database, the role of the command:

  1. If the database does not exist it is created, there is not created. --- IF NOT EXISTS
  2. Create a database, and set the code set to utf8 --- CHARSET utf8 COLLATE utf8_general_c
The CREATE  DATABASE  IF  the NOT  EXISTS database name of the DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

3. Use Database

USE database name;

note:

  Can not be used after the other databases, and other data in the data table operation, only the operation of the database itself

prompt:

  Operate on other database can be used to return to the SHOW DATABASES root directory

4. View the table

show tables;

5. Delete Database

drop  Database database name;

6. Create a data table

CREATE TABLE table_name (column_name column_type);

7. Delete Data Sheet

DROP TABLE table_name ;

8. Exit MYSQL:

 

quit 
 
 exit

9. Insert data

INSERT INTO table_name ( field1, field2,...fieldN )VALUES( value1, value2,...valueN );

Tip: If the data is character, must use single or double quotes, such as: "value".

10. The modified data update

  You can specify any condition in the WHERE clause.

UPDATE table_name SET field1='value' WHERE `id`>10

11. Delete data DELETE FROM 

DELETE FROM table_name WHERE `id`>10
  1. If you do not specify a WHERE clause, all records MySQL table will be deleted.
  2. You can specify any condition in the WHERE clause

Guess you like

Origin www.cnblogs.com/pipiyan/p/10975226.html