MySQL數(shù)據(jù)操作

-- 插入信息
-- 方法1:insert...values
-- 單條語(yǔ)句
insert into 表名 values (數(shù)據(jù));
    eg:
insert into class values (21403001,'張三','男',20,'重慶');

-- 多條語(yǔ)句
insert into 表名 values (數(shù)據(jù)),(數(shù)據(jù)),(數(shù)據(jù));
    eg:
insert into class values 
(null,'小花1','女',31,'河北3',null,null),
(null,'小花1','女',31,'河北3',null,null),
(null,'小花1','女',31,'河北3',null,null);

-- 方法2:insert...set
insert into 表名 set 字段1=值1,字段2=值2,...字段n=值n;
    eg:
insert into class set id=null,name='小花1',sex='女',age=32,address='河北3',birthday=null,remark=null;

-- 方法3:insert...select
insert into 插入的表 select * from 原表;
    eg:
insert into class1 select * from class;


-- 查詢數(shù)據(jù)
-- 方法1:查詢特定的行與列
select 字段 from 表名 where 條件表達(dá)式;
    eg:
select id, name from class where id<=21403005 and name<>'王五';
    --備注:查詢 字段 id<=21403005,但不包含 字段 name='王五' 的數(shù)據(jù);

-- 方法2:限制結(jié)果集
select * from 表名 limit 條數(shù);
eg:
select * from class limit 7;
-- 備注:數(shù)字是多少,就顯示多少條數(shù)據(jù)

-- 方法3:排序結(jié)果集
select * from 表名 order by 字段 asc;
eg:
select * from class order by name asc;
-- 備注:如果 字段 是數(shù)字,則按大小排序;如果是漢字或字母,則按字母排序;


-- 更新(修改)數(shù)據(jù)
update 表名 set 字段名=值,字段名=值,字段名=值,..... where 條件表達(dá)式;
eg:
update class set name = '張三',age='50' where id = 21403012;
    --備注: 修改 學(xué)號(hào) 為 21403012 的 姓名 和 年齡

-- 刪除數(shù)據(jù)
-- 方法1:如果不使用 where,則會(huì)刪除所有數(shù)據(jù)
delete from 表名 where [字段=值];
delete from 表名 where 條件表達(dá)式; 
-- 提交事務(wù)后生效,truncate不能保證事務(wù)的安全性。
eg:
delete from class2 where address="上海"; -- 指定字段 刪除 數(shù)據(jù)

-- 查看表
select * from 表名;
eg:
select * from class2;

-- 查看所有表
show tables;

-- 查看 表結(jié)構(gòu)
describe 表名;
eg:
describe class;

本文題目:MySQL數(shù)據(jù)操作
文章源于:http://muchs.cn/article36/ghshpg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營(yíng)銷推廣面包屑導(dǎo)航、用戶體驗(yàn)、App設(shè)計(jì)、響應(yīng)式網(wǎng)站、定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁(yè)設(shè)計(jì)