MySQL學習筆記(4)之資料操作

來源:互聯網
上載者:User

標籤:mysql   學習筆記   mysql入門   

資料操作:(insert into)

1、增加資料:

Insert into 表名 (欄位名) values (資料列表);

Insert into 表名 (欄位名) values (欄位列表1),(欄位列表2)....;

Insert into 表名 set 欄位1=值1,.........;

注釋:資料出現空缺或未指定部分欄位,則使用預設值NULL。

不使用預設值 (欄位列表 not null)

自訂預設值 (欄位列表 not null dfault ‘預設值’)

 

插入主鍵:

not null auto_increment primary key 未指定初始值的自動增量主鍵

Not null identity(1,1) primary key  指定初始值的自動增量主鍵

Not null unique primary key 非增量主鍵

 

2、使用select從其他表調用資料:

Insert into 表名 select * from 其他表 where ...order by.....limit......;

注釋:取代部分對應類型一定要相同。


3、替換資料:

Replace into ......;(和插入相同)

區別:

Insert   直接插入。

Replace 先判斷表中的主鍵或唯一索引欄位是否有和插入資料相應的值一樣的資料,他就變成修改。(先刪除舊資料再插入新資料)

 

4、查詢資料:

Select * from 表名 ;(查詢表中所有資料)


5、查詢條件:

Select * from 表名 where 條件;


6、修改資料:

Update 表名 set 欄位名=新值,....where 條件 order by ....... Limit ....;

注釋:不加條件則修改所有,謹慎使用。


7、刪除資料:

Delete from 表名 where ..... Order by ..... limit .....;

注釋:不加條件則刪除所有,謹慎使用。

 

列操作為DDL語言不是SQL語言。


本文出自 “一起學習交流” 部落格,請務必保留此出處http://chenhaolinux.blog.51cto.com/9609922/1710767

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.