Mysql常用命令(4) 插入、查詢、刪除、修改資料

來源:互聯網
上載者:User

標籤:point   tables   插入資料   blank   chm   rom   insert   技術   .com   

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>

查詢所有資料.png (30.95 KB, 下載次數: 0)

下載附件

2016-6-25 14:32 上傳

 


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)

http://www.sodu666.com/1/
http://tieba.sodu666.com/

Mysql常用命令(4) 插入、查詢、刪除、修改資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.