One: MySQL Basic Statement
1. Show available databases
show databases;
2. Create a library database
Create databaselibrary;
3. Using the Database
Use library;
4. View the table
Show tables;
5. Build a Table statement
Mysql> uselibrary;
Database changed
Mysql> createtable Viedos (
-video_id Int (one) not nullauto_increment,
-Title varchar (255) NOT NULL,
Director varchar (255) NOT NULL,
Primary KEY (video_id));
Query OK, 0 rowsaffected (0.30 sec)
6. Inserting data
Insert Intoviedos (Video_id,title,director) values
(1, ' Greater Shanghai ', ' action movies '), (2, ' Little Shanghai ', ' Love Movie '), (3, ' Red Shanghai ', ' comedy '), (4, ' Black Shanghai ', ' gun Shot '), (5, ' Big Shanghai ', ' sanda film ');
7. Delete a table
Delete from table_name;
8. Updating table data
Update Viedos settitle= ' on the beach ' where video_id=1;
Second: Execute the query statement
A: Basic statement
1. Search All
SELECT * FROMVIEDOS;
2. Query section
SELECT title Fromviedos;
3. Remove the same part of the query result
SELECT distinct title from Viedos;
SELECT title from Viedoswhere director= ' action movies ';
B: Using logical comparison operators
Create a new table:
CREATE TABLE Core (
Sname VARCHAR (+) not NULL,
Math INT not NULL,
Physics INT Notnull,
Literature INT Notnull)
Inserting data
INSERT into Corevalues (' John ', 68,37,45), (' Jim ', 96,89,92),
(' Bill ', 65,12,45), (' Harry ', 68,25,82);
Query 1:
SELECT * from Corewhere math>90;
Query 2:
SELECT sname Fromcore WHERE math>85;
Query 3:
SELECT * from Corewhere math<=25 or physics<=25 or literature<=25;
Query 4:
Selectsname,math+physics+literature from Core;
C: Using function queries
Query 1:
SELECT COUNT (*) from core;
Query 2:
SELECT AVG (math) from core;
Query 3:
Selectmin (math), MAX (physics) from core;
D: Filter Query Results
Query 1: Descending
SELECT Math Fromcore ORDER by math DESC;
Query 2: Show two records
SELECT Math Fromcore LIMIT 2, 2;
Query 3: Federated use
SELECT Math Fromcore ORDER by math DESC LIMIT 2, 2;
E: Using wildcard characters to query
Query 1:
SELECT sname fromcore WHERE sname like '%j% ';
Query 2:
SELECT Math fromcore WHERE math like '%6% ';
Copyright Notice: Bo Master original articles, reproduced please indicate the source. Http://blog.csdn.net/dzy21
Basic usage of MySQL query statement