mysql - 動作表

來源:互聯網
上載者:User

標籤:

1. 建立表  

 CREATE TABLE table_name(    field1 data_type [not null],    ...    field5 data_type [not null],  );
例子:
CREATE TABLE Student(
    Sno char(7) not null primary key,
    Sname varchar(10) not null,
    Ssex char(2),
    Sage integer
)

資料類型CHAR(定長字元):通常使用空格來填充數量不足的字元。不要使用定長字元來儲存長度不定的資料,比如姓名,否則可能會導致浪費可用空間,影響對不同的資料進行精確比較。

VARCHAR(變長字元)

2.修改表

可以添加列、刪除列、修改列定義、添加和去除約束。

alter table table_name [modify] [column column_name ] [datatype|null not null] [restrict|cascade]               [drop] [constraint constraint_name]               [add] [column] column definition

3.從現有表建立另一個表

利用CREATE TABLE和SELECT語句的組合可以複製現有表。

create table new_table_name as select [*|column1, column2] from table_name [where]

4.刪除表

drop table table_name [restrict|cascade]

如果使用了restrict選項,並且表被視圖或約束所引用,DROP語句就會返回一個錯誤。當使用了cascade選項時,刪除操作就會成功執行,而且全部引用視圖和約束都被刪除。

 

 

===================================================================================================

1.命令列登陸本地mysql

mysql -h localhost -u username -p password

2.告訴mysql我們要用哪個資料庫:

use mydb;

3.列出該db所有的表:

show tables;

4.列出表的所有欄位和屬性(describe):

desc table_name;

mysql - 動作表

聯繫我們

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