Add and delete change to learn first!
1: Numbers without double quotes
2. Strings must be double-quoted
3:
Update
All lines of words: Update
Pointing line: Update
Who you want to update is the line you want to change!
There are a few key questions to keep in mind! Change
Which table to change! (1)
2: You need to change the value of which columns!
3: What value are they changed into?
4: Which lines are in effect?
5;set: It's for setting new values!
6;update Plus Table Set
7; Column 1 = new value 1;
8; Column 2 = new value 2;
9; This column I changed to what value;
10; with where expr
11. In which lines are in effect you have to add a where condition
12;update user set age-8 where name= ' Lilei ';
13. Which table is taken, user table, set which column age-8; ,
14; in which line is in effect, whose name equals Lilei is in effect.
Column Sub Two:
1;update user to change this is called the user table
2; To change their columns set a bit;
3; To change their age equals 9. Age=9,
4, also want to change name= ' NOBO ' name= ' NOBO ';
5, for example, you want to change, a lot of students do you want to change who?
6; now where uid=2;
7; I use where number second user uid;
9; Tell me where the purpose is and you can do it.
Error: If the data is wrong. It's ruined.
You can set a novice mode;
He's not doing it without a where.
Do not add where all the lines are executed L is very dangerous;
Example three deletions:
1: Which table data do you want to delete? With the delete from table name:
2:
What rows do you want to delete? Use where expr to denote a case:
3:delete fron user where uid=4;
4: Delete is not followed by the upstream and the column
5: Because you can't just delete a row or column, you need to remove the
6:xxx:delete from user; It's a mistake to write, isn't it? All the data is erased.
Remove is delete from + table name +where + which line is OK
Delete fron user where uid=4;
Now it is checked and deleted and modified to check!
Select Check
1:select column 1, column 2 column: From table name
where expr
Which table data do you look for?
Which columns do you want to select for queries?
Do you want to select those rows?
Inquiry form show databases;
Finished at this time out of the table;
Add table is this code creata database day15;
There is a day15 in the table that appears.
The above is the default way to create;
There is one other thing
Creata Database Day15
Default character set UTF8;
This is also a kind of creation.
means to send.
Specify a default character set to create a database
3; now look at how to query the character set database;
Show CREATE Database day15;
is to see the meaning of the character set; I wipe.
+----------+----------------------------------------------------------------+
| Database | Create Database |
+----------+----------------------------------------------------------------+
| DAY15 | CREATE DATABASE ' day15 '/*!40100 DEFAULT CHARACTER SET UTF8 */| |
+----------+----------------------------------------------------------------
4: Now speak of deleting the database;
Drop database day15;
is to delete the database
: 5: The database is now modified;
mysql> ALTER DATABASE DAY15 default character set GBK; This is to modify the path to GBK
Query OK, 1 row affected this is to show that the modification was successful
Mysql> Show CREATE Database day15; This is a lost one. To look at the current character set
+----------+---------------------------------------------------------------+
| Database | Create Database |
+----------+---------------------------------------------------------------+
| DAY15 | CREATE DATABASE ' day15 '/*!40100 DEFAULT CHARACTER SET GBK */| |
+----------+---------------------------------------------------------------+
1 row in set well, it's been changed to GBK.
Modify database Alter DAY15; Modify the database notation
View database show databases;
add databases; creata database day15;
Drop database day15;
6. Management of Tables
First select the database and then look up the table
1. Select Database Use
Use DAY15;
2: Finished viewing DAY15 's table tables;
Show tables;
3: CREATE TABLE
CREATE TABLE Student (
Field format:
Field Name: Field type
Field Name: Field type
(3,1) Create a table below this is a demo
CREATE TABLE Student (
Sid Int,
sname varchar (20),
Sage int);
int represents an integer and represents a later
(3,2) Enquiry form:
mysql> use DAY15;
Database changed
Mysql> Show tables;
Empty Set
No performance in creating tables:
Mysql> CREATE TABLE Student (
-Sid int,
sname varchar (20),
Sage INT
);
Query OK, 0 rows affected
Now we're calling the previous lookup table.
3.3) mysql> show tables;
+-----------------+
| TABLES_IN_DAY15 |
+-----------------+
| Student |
| stydent |
+-----------------+
2 rows in Set
Okay, now the creation table is done!
Represents the meaning of the length character
Field format:
View all tables the first step;
Show tables;
7: View the structure of a table!
mysql> desc Student;
Appearance diagram
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Sid | Int (11) | YES | | NULL | |
| sname | varchar (20) | YES | | NULL | |
| Sage | Int (11) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 Rows in Set
5 "3 View the structure of the table; Delete a table
Delete is drop table student; (Delete the meaning of the table);
5 "4 Modify Table
ALTER TABLE (field to modify tables) case Demo:
Mysql> ALTER TABLE student add column Sgender varchar (2);
Query OK, 0 rows affected
records:0 duplicates:0 warnings:0
Then search the table. DESC student;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| Sid | Int (11) | YES | | NULL | |
| sname | varchar (20) | YES | | NULL | |
| Sage | Int (11) | YES | | NULL | |
| Remark | varchar (20) | YES | | NULL | |
| Sgender | varchar (2) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
5 rows in Set
6: Delete Table
Mysql> code: ALTER TABLE student drop column sgender;
Query OK, 0 rows affected
records:0 duplicates:0 warnings:0
Then check the DESC studet;
mysql> desc Student;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| Sid | Int (11) | YES | | NULL | |
| sname | varchar (20) | YES | | NULL | |
| Sage | Int (11) | YES | | NULL | |
| Remark | varchar (20) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
4 rows in Set
That's it, sgender. This table is erased. He doesn't have to use that, not a few lines of stuff, because he just found him.
Keyboard up key is the bottom of the mountain can see you enter the code artifact AH
Learn MySQL precautions!