MySQL DBA combat operation and maintenance

DML
purpose
in MySQL management software, DDL has been defined database structure.
So how to manage the data which it?
Operating data can be achieved through the SQL statement DML language, including the use
INSERT to insert data to achieve the
DELETE realize delete data
UPDATE realize update data.
First, insert data INSERT
complete insertion
syntax
INSERT INTO table name VALUES (value 1, value 2 and value 3 ... value n-);
operating
slightly
partly inserted
syntax
INSERT INTO table name (column name, column name) VALUES (value 1, value 2 );
operation
slightly
II uPDATE update data
syntax
uPDATE SET table column name = value WHERE CONDITION;
exemplary
prepare a table
MySQL> Create table T6 (int ID, name VARCHAR (20 is));
MySQL> INSERT INTO T6 values (. 1 , 'AA');
MySQL> INSERT iNTO T6 values (2, 'bb');
updating data
requirements: the change bb cc
mysql> update t6 set name = ' cc' where id = 2;
Results
mysql> select * from t6;
three, delete the data DELETE
Syntax:
DELETE the FROM table name WHERE CONDITION;
example:
Demand: Remove id recorded for the user 2.
mysql> delete from t6 where id = 2;
please without thinking where the conditions will be.
DQL
purpose
in MySQL management software, the data can be achieved through the SQL statement language DQL
SELECT query operation
of Internet users check balances, operating equipment inquiries, inquiries goods.
MySQL query
Preparation environment
preparing a table comprising
three information
id int ID
name varchar name
age int Age
exemplary
create table t3 (id int, name varchar (20), age int);
then insert the test data
insert into t3 values (1 , "zhangsan", 23 is);
INSERT INTO T3 values (2, "Lisi", 24);
insert into t3 values (3, " wangwu", 18);
a simple query
a simple query
to see all the columns
premise is the need to enter the database.
Do not enter the database, please enter the library name.
SELECT * FROM table name;
check column portion
SELECT column 1, row 2, column 3 FROM table name;
two, single condition search
example: Only check information seating
SELECT * FROM table name WHERE name = 'zhangsan';
Equal attention right letters, single quotation marks need to
pay attention to the right of the equal sign is a number, not quoted
three queries ordered
e.g. age ascending
column names the ASC SELECT * FROM table name oRDER BY age;
e.g. age descending
SELECT * FROM column name DESC table name ORDER BY age;
Fourth, limit the number of records the query
grades up before 3
SELECT * FROM table name ORDER BY column names age DESC lIMIT 3;

Published 16 original articles · won praise 0 · Views 535

Guess you like

Origin blog.csdn.net/QAQkira/article/details/104851086