MySQL資料庫基礎回顧

來源:互聯網
上載者:User

   一、資料表

  為了確保資料的完整性和一致性,在建立表時指定欄位名稱,欄位類型和欄位屬性外,還需要使用約束(constraint),索引(index),主鍵(primary key)和外鍵(foregin key)等。

  約束條件:

  not null 非空約束

  unique 唯一性限制式

  primary key 主鍵約束

  foreign key 外鍵約束

  check 檢查約束

  auto_increment 自動識別欄位(值會自動增1)

  建立表:

  修改表:

  修改表的結構,如修改列的類型,添加新的欄位,刪除原有欄位,更改表名稱

  alter%20table%20user%20modify/add/drop/change/rename

  刪除表:

  添加資料(一次添加一條和一次添加多條)

  查詢:

  修改表資料:

  刪除表中記錄:

  當表中欄位很長時:書寫不方便,我們可以使用as給欄位起別名:

  去掉查詢中重複,使用distinct

  查詢數值在某一範圍:select * from user where age between.. and ..

  查詢在給出值的集合中的值:select * from user where name in('"lixq", "lxq");

  模糊查詢:

  %:代表0到多個字元

  _:代表一個任一字元

  二、索引

  索引在資料庫開發中,可以提高查詢最佳化,確保資料的唯一性,以及可以對任何全文索引欄位中大量文本的搜尋進行最佳化,索引的分類:主鍵索引(primary key),唯一索引(unique),常規索引(index),全文索引(fulltext);

  三、資料庫表類型及儲存位置

  Mysql支援MYISAM,InnoDB,MEMORY等多種資料表類型

  查看當前資料庫支援儲存引擎

  一般在mysql的安裝目錄下的data檔案中儲存資料表

  四、資料表的預設字元集

  在mysql資料庫中,可以為資料庫,資料表,甚至每一個資料列分別設定一個不同的字元集,使用create table命令建立資料庫時,若沒有指定任何字元集,則是mysql設定檔裡character-set-server選項決定的。

  修改按照目錄下的my.ini檔案

?

1 2 <strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>default-character-set=utf8 character-set-server=utf8</strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong>

  windows中顯示中文會出現問題,加一個set names gbk 顯示就會正常

聯繫我們

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