MySQL之表操作

來源:互聯網
上載者:User

標籤:alt   inno   from   key   htm   lte   nbsp   資料   條件   

一、建立表  1、建立新表
#文法:create table 表名(欄位名1 類型[(寬度) 約束條件],欄位名2 類型[(寬度) 約束條件],欄位名3 類型[(寬度) 約束條件]);#注意:1. 在同一張表中,欄位名是不能相同2. 寬度和約束條件可選3. 欄位名和類型是必須的

 

mysql> create table auth(    -> id int(10) primary key auto_increment,    -> name varchar(10) not null,    -> age int(3),    -> birthday datetime    -> );Query OK, 0 rows affected (0.36 sec)

  

  2、複製表

 

mysql> create table auth2 select * from auth;Query OK, 0 rows affected (0.29 sec)Records: 0  Duplicates: 0  Warnings: 0

  

二、查看錶  1、查看錶結構
mysql> desc auth;+----------+-------------+------+-----+---------+----------------+| Field    | Type        | Null | Key | Default | Extra          |+----------+-------------+------+-----+---------+----------------+| id       | int(10)     | NO   | PRI | NULL    | auto_increment || name     | varchar(10) | NO   |     | NULL    |                || age      | int(3)      | YES  |     | NULL    |                || birthday | datetime    | YES  |     | NULL    |                |+----------+-------------+------+-----+---------+----------------+4 rows in set (0.02 sec)
  2、查看錶的建立資訊
mysql> show create table auth;+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table                                                                                                                                                                                                            |+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| auth  | CREATE TABLE `auth` (  `id` int(10) NOT NULL AUTO_INCREMENT,  `name` varchar(10) NOT NULL,  `age` int(3) DEFAULT NULL,  `birthday` datetime DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 |+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)

  

三、修改表  1、修改表名稱
mysql> alter table auth2 rename auth666;Query OK, 0 rows affected (0.10 sec)
  2、增加表欄位
mysql> alter table auth add addr char(6) not null;Query OK, 0 rows affected (0.53 sec)Records: 0  Duplicates: 0  Warnings: 0
  3、修改表欄位

修改表欄位資訊

mysql> alter table auth modify addr varchar(6) null;Query OK, 0 rows affected (0.60 sec)Records: 0  Duplicates: 0  Warnings: 0

 修改表欄位名以及欄位資訊

mysql> alter table auth change addr address varchar(6);Query OK, 0 rows affected (0.09 sec)Records: 0  Duplicates: 0  Warnings: 0
  4.刪除表欄位
mysql> alter table auth drop birthday;Query OK, 0 rows affected (0.49 sec)Records: 0  Duplicates: 0  Warnings: 0
四、刪除表
mysql> drop table auth666;Query OK, 0 rows affected (0.10 sec)
五、表的資料類型

http://www.cnblogs.com/fu-yong/p/8495001.html

六、表的約束

http://www.cnblogs.com/fu-yong/p/8495003.html

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.