insert into命令用於向表中插入數據。
insert into命令格式:insert into <表名> [(<字段名1>[,..<字段名n > ])] values ( 值1 )[, ( 值n )];
先show tables;有個MyClass 表。往表 MyClass中插入兩條記錄,這兩條記錄表示:編號為1的名為Tom的成績為96.45,編號為2 的名為Joan 的成績為82.99,編號為3 的名為Wang 的成績為96.5。
[SQL]
純文本查看
復制代碼
insert into MyClass values(null,'Tom',1,96.45),(null,'Joan',1,82.99), (null,'Wang',2, 96.59);
select from命令用來查詢表中的數據。
命令格式: select <字段1, 字段2, ...> from < 表名 > where < 表達式 >;
例如,查看表 MyClass 中所有數據:
[SQL]
純文本查看
復制代碼
slect * from MyClass;
查詢結果如圖:
<ignore_js_op> 
delete from命令用於刪除表中的數據。
delete from命令格式:delete from 表名 where 表達式
例如,刪除表 MyClass中編號為1 的記錄:
[SQL]
純文本查看
復制代碼
delete from MyClass where id=1;
刪除后表里的數據如下:
[SQL]
純文本查看
復制代碼
mysql> Select * from MyClass; +----+------+-----+--------+ | id | name | sex | degree | +----+------+-----+--------+ | 2 | Joan | 1 | 82.99 | | 3 | Wang | 2 | 96.59 | +----+------+-----+--------+ 2 rows in set (0.00 sec)
update set命令用來修改表中的數據。
update set命令格式:update 表名 set 字段=新值,… where 條件;
舉例如下:
[Shell]
純文本查看
復制代碼
update MyClass set name='ck' where id=2;
更新后數據如下:
[SQL]
純文本查看
復制代碼
mysql> select * from MyClass; +----+------+-----+--------+ | id | name | sex | degree | +----+------+-----+--------+ | 2 | ck | 1 | 82.99 | | 3 | Wang | 2 | 96.59 | +----+------+-----+--------+ 2 rows in set (0.00 sec)
