MySQL學習筆記之建立、刪除、修改表的方法_Mysql

來源:互聯網
上載者:User

本文執行個體講述了MySQL學習筆記之建立、刪除、修改表的方法。分享給大家供大家參考,具體如下:

建立表:

create table users(  id int,  name varchar(64),  sex bit(1),  birthday date,  Entry_date date,  job varchar(32),  salary float,  resume text);

1 添加列:

alter table 表名 add 列名 資料類型

alter table users add image blob;

2 修改列:

alter table 表名 modify 列名 新的資料類型(資料長度大小)

alter table users modify sex char(2);

3 刪除列:

alter table 表名 drop 列名

alter table users drop image;

4 修改表名:

rename table 表名 to  新表名

rename table users to user;

5 修改表的字元集:

alter table 表名 character set 字元集

alter table user character set gbk

6 修改列名字:

alter table 表名 change column 原列名 新列名 類型

alter table users change column sex sexy varchar(2);

7 查看錶結構:

mysql> describe users;+------------+-------------+------+-----+---------+-------+| Field   | Type    | Null | Key | Default | Extra |+------------+-------------+------+-----+---------+-------+| id     | int(11)   | YES |   | NULL  |    || name    | varchar(64) | YES |   | NULL  |    || sex    | bit(1)   | YES |   | NULL  |    || birthday  | date    | YES |   | NULL  |    || Entry_date | date    | YES |   | NULL  |    || job    | varchar(32) | YES |   | NULL  |    || salary   | float    | YES |   | NULL  |    || resume   | text    | YES |   | NULL  |    |

8 查看錶建立結構:

mysql> show create table users;

9 刪除表:

mysql> drop table test9;

更多關於MySQL相關內容感興趣的讀者可查看本站專題:《MySQL索引操作技巧匯總》、《MySQL日誌操作技巧大全》、《MySQL事務操作技巧匯總》、《MySQL預存程序技巧大全》、《MySQL資料庫鎖相關技巧匯總》及《MySQL常用函數大匯總》

希望本文所述對大家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.