MySQL精華學習 資料庫的 SQL 文法參考

來源:互聯網
上載者:User

一、資料定義 ddl(data definition language)

  資料定語言是指對資料的格式和形態下定義的語言,他是每個資料庫要建立時候時首先要面對的,舉凡資料分哪些表格關係、表格內的有什麽欄位主鍵、表格和表格之間互相參考的關係等等,都是在開始的時候所必須規劃好的。

  1、建表格:

create table table_name(
column1 datatype [not null] [not null primary key],
column2 datatype [not null],
...);

  說明: 

datatype --是資料的格式,詳見表。
nut null --可不可以允許資料有空的(尚未有資料填入)。
primary key --是本表的主鍵。

  2、更改表格 

alter table table_name
add column column_name datatype

  說明:增加一個欄位(沒有刪除某個欄位的文法。

alter table table_name
add primary key (column_name)

  說明:更改表得的定義把某個欄位設為主鍵。

alter table table_name
drop primary key (column_name)

  說明:把主鍵的定義刪除。

  3、建立索引 

create index index_name on table_name (column_name)

  說明:對某個表格的欄位建立索引以增加查詢時的速度。

  4、刪除 

drop table_name
drop index_name

  • 1
  • 2
  • 下一頁
【內容導航】
第1頁:資料定義 第2頁:資料操作

聯繫我們

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