创建表格
create table product
( product_id char(4) not null,
product_name varchar(100) not null,
product_type varchar(20) not null,
create_time date,
update_time date,
primary key(product_id)
);
修改表名称
//rename table 表名 to 修改后名称
rename table product to product_1
修改列名
// alter table 表名 rename column 列名 to 新的列名
alter table product rename column product_type to product_type1;
加入字段进入表中
// 参考代码
insert into 表名(对应列名) values(对应值)
mysql> select * from product;
+------------+--------------+--------------+------------+----------------+-------------+-------------+
| product_id | product_name | product_type | sale_price | purchase_price | regist_date | create_name |
+------------+--------------+--------------+------------+----------------+-------------+-------------+
| 0001 | ?? | ?? | 100 | 80 | 2009-10-10 | NULL |
| 0002 | drawer | 3 | 200 | 160 | 2010-08-21 | NULL |
+------------+--------------+--------------+------------+----------------+-------------+-------------+
// 按照上面的都结构应该是
insert into product(product_id,
product_name,
product_type,
sale_price,
purchase_price,
regist_date,
update_date
) values (
"0003",
"裤子",
"夏季",
"120",
"86",
"2009-10-12",
"2010-03-12"
)
添加,减少列
//参照格式
// alert table 表名 drop column 列名 删除列
// alert table 表名 add column 列名 增加列
alter table product drop column product_name
alter table product add column product_name