Add update data deletion

1. Add the data
required to create a new record in a database prior to addition itcast, create a database SQL statement is as follows:
MySQL> the CREATE DATABASE itcast; Query the OK, affected. 1 Row

Select database itcast, the following SQL statement:
MySQL> the USE itcast ;
database changed

to create a table in the database for storing student1_tb student information, creating tables student_tb SQL statement is as follows:
MySQL> the CREATE tABLE student1_tb
    -> (
    -> the INT ID (20 is) a PRIMARY KEY,
    -> name VARCHAR (20 is ) the NOT NULL,
    -> Sex VARCHAR (10) UNIQUE,
    -> Grade FLOAT
    ->);
Query the OK, 0 rows affected

to view the contents of student1_tb
MySQL> the DESCRIBE student1_tb;
+ ------- + ---- + ------ + ----- + --------- + --------- + -------
| Field, | Type | Null | Key | Default | Extra |
+ ------- + ------------- + --------- + ------ + ----- + ---- + ---
| ID | int (20 is) | NO | the PRI | NULL | |
| name | VARCHAR (20 is) | NO | | NULL | |
| Sex | VARCHAR (10) | YES | the UNI | NULL | |
| Grade | float | YES | | NULL | |
+ ------------- + ------- + ------ + ----- + ----- + ------- + ----
. 4 in rows SET

using iNSERT statement to insert a row into table student_tb, SQL statements as follows:
MySQL> iNSERT the iNTO student1_tb (ID, name, Sex, Grade) the VALUES ( . 1, "zhangsan", "NaN3", 98.5);
Query the OK,. 1 Row affected


when the above SQL statement is executed successfully, adds a data table in student1_tb. In order to verify whether the data is successfully added, using the SELECT statement to view data student_tb table, query results are as follows:
MySQL> SELECT * the FROM student1_tb;
+ ---- + ------ + ----- + --- + ----
| the above mentioned id | name | Sex | Grade |
---- + ------ + ----- + + ------- +
| 1 | zhangsan | NaN | 98.5 |
+ ---- + ------ + - + ------- + ----
. 1 in SET Row

continue to add data to student1_tb;
MySQL> the INSERT the INTO student1_tb (ID, name, Sex, Grade) the VALUES (2, "Lisi", "NaN3", 95 );
Query the OK,. 1 Row affected

MySQL> the INSERT the INTO student1_tb (ID, name, Sex, Grade) the VALUES (. 3, "wangwu", "NV", 61.5);
Query the OK,. 1 Row affected

verify added successfully;
MySQL> * the FROM student1_tb the SELECT;
+ ---- + ------ + ----- + ------- +
| the above mentioned id | name | Sex | Grade |
+ ---- + --- + ----- + ------- + ---
| 1 | zhangsan | NaN | 98.5 |
| 2 | lisi | NaN | 95 |
| 3 | wangwu | nv | 61.5 |
+ ---- ------ ------- + ----- + + +
. 3 in rows SET

2.update data
UPDATE updating partial data
mysql> UPDATE student1_tb set name = "Oh", Grade = 95 the WHERE id =. 7;
Query the OK,. 1 Row affected
the Rows Matched:. 1 the Changed:. 1 Warnings: 0


Update student1_tb table id field recorded less than 4 values the grade field values of these records are updated to 100.
MySQL> the UPDATE student1_tb SET grade = 100 the WHERE id <4;
Query the OK, 2 rows affected
the Rows Matched:. 3 the Changed: 2 Warnings: 0

. 3 rows in SET
update student1_tb table id field value of the recording is less than 4, the grade field values updated to 80.
MySQL> student1_tb the UPDATE SET Grade = 80;
Query the OK,. 7 rows affected
the Rows Matched: the Changed. 7: Warnings. 7: 0

Third, delete data
in student1_tb table, delete record id field value of 6:
MySQL> the DELETE the FROM student1_tb the WHERE id . 6 =;
Query the OK, Row affected. 1


in student1_tb table, delete the record id field is greater than 3:
MySQL> DELETE the FROM student1_tb the WHERE the above mentioned id> 3;
Query the OK, 3 rows affected

delete all data
MySQL> DELETE the FROM student1_tb;
Query the OK, 3 rows affected

again viewed through query record student1_tb table, the results are as follows:
MySQL> * the FROM student1_tb the SELECT;
Empty the SET

Guess you like

Origin www.cnblogs.com/cmja/p/11827289.html