MySQL DML操作の詳細

3634 ワード

一、データベースDML操作(添削)
1.従業員テーブルの作成
--        
create table t_employee (
 id bigint primary key auto_increment,
 name varchar(20) not null,
 gender varchar(10),
 birthday date,
 entry_date date,
 job varchar(30),
 salary double,
 resume text
 );

mysql> desc t_employee;
+------------+-------------+------+-----+---------+----------------+
| Field      | Type        | Null | Key | Default | Extra          |
+------------+-------------+------+-----+---------+----------------+
| id         | bigint(20)  | NO   | PRI | NULL    | auto_increment |
| name       | varchar(20) | NO   |     | NULL    |                |
| gender     | varchar(10) | YES  |     | NULL    |                |
| birthday   | date        | YES  |     | NULL    |                |
| entry_date | date        | YES  |     | NULL    |                |
| job        | varchar(30) | YES  |     | NULL    |                |
| salary     | double      | YES  |     | NULL    |                |
| resume     | text        | YES  |     | NULL    |                |
+------------+-------------+------+-----+---------+----------------+
8 rows in set (0.01 sec)

2.挿入文---insert
mysql> insert into t_employee (name,gender,job,salary,resume) values ('   ','
 ','  ','1000000','   ');
Query OK, 1 row affected (0.08 sec)

mysql> select * from t_employee;
+----+--------+--------+----------+------------+------+---------+--------+
| id | name   | gender | birthday | entry_date | job  | salary  | resume |
+----+--------+--------+----------+------------+------+---------+--------+
|  1 |      |       | NULL     | NULL       |    | 1000000  |     |
+----+--------+--------+----------+------------+------+---------+--------+
1 row in set (0.01 sec)

3.更新文---update

--  1、   id=2 name='   ',birthday='1975-10-10'

mysql> update t_employee set name='   ',birthday='1975-10-10' where id=2 ;
Query OK, 1 row affected (0.08 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from t_employee;
+----+--------+--------+------------+------------+------+---------+--------+
| id | name   | gender | birthday   | entry_date | job  | salary  | resume |
+----+--------+--------+------------+------------+------+---------+--------+
|  1 |     |       | NULL       | NULL       |    | 1000000 |     |
|  2 |     |       | 1975-10-10 | NULL       |    | 1000000 |     |
|  3 |     |       | NULL       | NULL       |    | 1000000 |     |
|  4 |     |       | NULL       | NULL       |    | 1000000 |     |
|  5 |     |       | NULL       | NULL       |    | 1000000 |     |
+----+--------+--------+------------+------------+------+---------+--------+
5 rows in set (0.02 sec)

    4.削除文---delete

--  1、    ID=3   。
delete from t_employee where id=3;

Query OK, 1 row affected (0.08 sec)

mysql> select * from t_employee;
+----+--------+--------+------------+------------+------+---------+--------+
| id | name   | gender | birthday   | entry_date | job  | salary  | resume |
+----+--------+--------+------------+------------+------+---------+--------+
|  1 |     |       | NULL       | NULL       |    | 1000000 |     |
|  2 |     |       | 1975-10-10 | NULL       |    | 1000000 |     |
|  4 |     |       | NULL       | NULL       |    | 1000000 |     |
|  5 |     |       | NULL       | NULL       |    | 1000000 |     |
+----+--------+--------+------------+------------+------+---------+--------+
4 rows in set (0.00 sec)

--    2、        。
 delete from t_employee;