MySQL之DML語句(insert update delete)

來源:互聯網
上載者:User

標籤:操作   where   jason   color   指定   from   mysql   nbsp   let   

DML主要針對資料庫表對象的資料而言的,一般DML完成:

  插入新資料

  修改已添加的資料

  刪除不需要的資料

1、insert into插入語句

//主鍵自增可以不插入,所以用null代替insert into temp values(null, ‘jack‘, 25);//指定列insert into temp(name, age) values(‘jack‘, 22);在表面後面帶括弧,括弧中寫列名,values中寫指定列名的值即可。當省略列名就表示插入全部資料,注意插入值的順序和列的順序需要保持一致。//set方式插入,也可以指定列insert into temp set id = 7, name = ‘jason‘;//MySQL中外鍵的table的外鍵引用可以插入資料可以為null,不參照主表的資料。//使用子查詢插入資料insert into temp(name) select name from classes;//多行插入insert into temp values(null, ‘jack‘, 22), (null, ‘jackson‘, 23);

 

2、update修改語句

update主要完成對資料的修改操作,可以修改一條或多條資料。

修改多條或指定條件的資料,需要用where條件來完成。

//修改所有資料update temp set name = ‘jack2‘;//所有的資料的name會被修改,如果修改多列用“,”分開update temp set name = ‘jack‘, age = 22;//修改指定條件的記錄需要用whereupdate temp set name = ‘jack‘ where age > 22;

 

3、delete刪除語句

刪除table 中的資料,可以刪除所有,帶條件可以刪除指定的記錄。

//刪除所有資料delete from temp;//刪除指定條件資料delete from temp where age > 20;

 

MySQL之DML語句(insert update delete)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.