创建表格

  1. create table product
  2. ( product_id char(4) not null,
  3. product_name varchar(100) not null,
  4. product_type varchar(20) not null,
  5. create_time date,
  6. update_time date,
  7. primary key(product_id)
  8. );

修改表名称

//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