標籤: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之表操作