创建数据表
CREATE TABLE test_table (
ID int ,
Name varchar( 255 )
) ;
"""
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test_table |
+----------------+
1 row in set (0.00 sec)
"""
增
INSERT INTO `test_table`( `ID`, `Name`) VALUES ( 1 , '张三' ) ;
INSERT INTO `test_table`( `ID`, `Name`) VALUES ( 1 , '张三' ) ;
INSERT INTO `test_table`( `ID`, `Name`) VALUES ( 2 , '李四' ) ;
INSERT INTO `test_table`( `ID`, `Name`) VALUES ( 2 , '李四' ) ;
INSERT INTO `test_table`( `ID`, `Name`) VALUES ( 3 , '王五' ) ;
"""
mysql> select * from test_table;
+------+--------+
| ID | Name |
+------+--------+
| 1 | 张三 |
| 1 | 张三 |
| 2 | 李四 |
| 2 | 李四 |
| 3 | 王五 |
+------+--------+
5 rows in set (0.00 sec)
"""
删
DELETE FROM `test_table` WHERE ID= 3 ;
"""
mysql> delete from test_table where ID=3;
Query OK, 1 row affected (0.00 sec)
mysql> select * from test_table;
+------+--------+
| ID | Name |
+------+--------+
| 1 | 张三 |
| 1 | 张三 |
| 2 | 李四 |
| 2 | 李四 |
+------+--------+
4 rows in set (0.00 sec)
"""
改
UPDATE test_table SET name= '王二' WHERE id = 3 ;
"""
mysql> update test_table set name='王二' where id=3;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from test_table;
+------+--------+
| ID | Name |
+------+--------+
| 1 | 张三 |
| 1 | 张三 |
| 2 | 李四 |
| 2 | 李四 |
| 3 | 王二 |
+------+--------+
5 rows in set (0.00 sec)
"""
查
select * from test_table;
"""
mysql> select * from test_table;
+------+--------+
| ID | Name |
+------+--------+
| 1 | 张三 |
| 1 | 张三 |
| 2 | 李四 |
| 2 | 李四 |
| 3 | 王二 |
+------+--------+
5 rows in set (0.00 sec)
"""
select * from test_table where id = 2 ;
"""
mysql> select * from test_table where id=2;
+------+--------+
| ID | Name |
+------+--------+
| 2 | 李四 |
| 2 | 李四 |
+------+--------+
2 rows in set (0.00 sec)
"""