1. 创建表

  1. # create table 表名 (各种字段)
  2. create table goods (id int primary key auto_increment, brandName varchar (100), shopName varchar (100), description varchar (200));

2. 查看表结构

  1. # desc 表名
  2. desc goods;

3. 删除表结构

  1. drop table goods if exists;

4.复制表结构

生成一些测试数据

  1. # insert into 表名 set 字段名="字段值",字段名="字段值",字段名="字段值";
  2. insert into goods set brandName="asus", shopName="ax86u",description="路由器";
  3. # insert into 表名 (字段名,字段名,字段名) values (值,值,值);
  4. insert into goods (brandName,shopName,description) values ("redmi","ax5400","另外一个路由器"),("redmi","ax5400","另外一个路由器");
  1. # create table 表名 like 要复制的表
  2. CREATE table test like goods;

5. 复制表中的数据

  1. # 查询所有的数据插入到test
  2. insert into test select * from goods;
  3. # 查询brandName shopName 插入到test中
  4. INSERT into test (brandName,shopName) select brandName,shopName from goods ;

6. 创建表的时候直接复制数据

  1. create table tableName select * from test;
  2. # 从test中的shopName 赋值给c表中的name(使用别名 as ...)
  3. create table c (id int primary key auto_increment , name varchar (100)) select shopName as name from test;