1. 创建表
# create table 表名 (各种字段)create table goods (id int primary key auto_increment, brandName varchar (100), shopName varchar (100), description varchar (200));
2. 查看表结构
# desc 表名desc goods;
3. 删除表结构
drop table goods if exists;
4.复制表结构
生成一些测试数据
# insert into 表名 set 字段名="字段值",字段名="字段值",字段名="字段值";insert into goods set brandName="asus", shopName="ax86u",description="路由器";# insert into 表名 (字段名,字段名,字段名) values (值,值,值);insert into goods (brandName,shopName,description) values ("redmi","ax5400","另外一个路由器"),("redmi","ax5400","另外一个路由器");
# create table 表名 like 要复制的表CREATE table test like goods;
5. 复制表中的数据
# 查询所有的数据插入到testinsert into test select * from goods;# 查询brandName shopName 插入到test中INSERT into test (brandName,shopName) select brandName,shopName from goods ;
6. 创建表的时候直接复制数据
create table tableName select * from test;# 从test中的shopName 赋值给c表中的name(使用别名 as ...)create table c (id int primary key auto_increment , name varchar (100)) select shopName as name from test;
