sql alter 修改字段类型与名称的方法
sql alter 修改字段类型与名称的方法
ALTER TABLE "table_name"
[改变方式]
加一个栏位: ADD "栏位 1" "栏位 1 资料种类"
mysql教程> CREATE TABLE Employee(
-> id int,
-> first_name VARCHAR(15),
-> last_name VARCHAR(15),
-> start_date DATE,
-> end_date DATE,
-> salary FLOAT(8,2),
-> city VARCHAR(10),
-> description VARCHAR(15)
-> );
Query OK, 0 rows affected (0.03 sec)mysql>
mysql>
mysql> ALTER TABLE employee
-> CHANGE First_Name FirstName VARCHAR(20);
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0mysql>
mysql> DESCRIBE employee;
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| FirstName | varchar(20) | YES | | NULL | |
| last_name | varchar(15) | YES | | NULL | |
| start_date | date | YES | | NULL | |
| end_date | date | YES | | NULL | |
| salary | float(8,2) | YES | | NULL | |
| city | varchar(10) | YES | | NULL | |
| description | varchar(15) | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
8 rows in set (0.01 sec)
修改字段为varchar类型
mysql> ALTER TABLE employee
-> CHANGE Last_Name Last_Name VARCHAR(50);
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
给个字段加个索引
mysql> ALTER TABLE myTable
-> ADD UNIQUE (OrderID, ModelID);
Query OK, 0 rows affected (0.06 sec)
补充:数据库,mysql教程