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