【MySQL筆記】資料定義語言 (Data Definition Language)DDL

來源:互聯網
上載者:User

標籤:

1、建立基本表     create table <表名> (<列名><資料類型>[列級完整性條件約束條件]                                                      [,<列名><資料類型>[列級完整性條件約束條件]                                                      .........                                                      [,<表級完整性條件約束條件>]); 例:
  1. create table student(
  2. Sno char(5) not null unique,
  3. Sname char(20) unique,
  4. Ssex char(1),
  5. Sage int,
  6. Sdept char(15)
  7. );

2、修改基本表              alert  table  <表名>                                   [add <新列名> <資料類型> [完整性條件約束]]                                   [drop <完整性條件約束名>]                                   [modify <列名><資料類型>]; 1)add: 用於向表中增加新列及新列相關的完整性條件約束條件,新的列增加成功後不帶任何資料
        alert table student add Scome date;
2)drop:用於刪除指定的完整性條件約束條件    
        alert table student drop unique(Sname);
 3)modify:用於修改原來的列定義,包括修改列名和資料類型,列資料類型修改後可能會丟失原有的資料         alert table student modify Sage smallint;
         註:SQL中沒有提供刪除屬性列的功能,若需要刪除列,必須間接通過select語句來實現,將需要的列的內容複寫到另一個表中,再刪除原表,然後將新表的名字命名為原表名 3、刪除基本表               drop table <表名> 4、建立與刪除索引 5.1建立            create [unique] [cluster] index <索引名> on <表名> (<列名> [<次序][,<列名>[<次序]].....);例:             create unique index studentIndex on student (sno);註:1)unique:表明此索引的每個索引值只對應惟一的一個記錄2)cluster:表時要建立的索引是聚簇索引,即按某一列建好索引後,硬碟上的資料存放區順序也調整為按這個列的順序儲存,索引的順序和儲存順序是一致的。
5.2刪除             drop index <索引名>;例:             drop index studentIndex;
連結:http://blog.csdn.net/zdwzzu2006/article/details/2298777


來自為知筆記(Wiz)

【MySQL筆記】資料定義語言 (Data Definition Language)DDL

聯繫我們

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