如何使用MySQL LIKE从第一个表创建新表?
让我们首先创建一个表-
create table DemoTable1 ( EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, EmployeeName varchar(50) );
使用插入命令在表中插入一些记录-
insert into DemoTable1(EmployeeName) values('Tom'); insert into DemoTable1(EmployeeName) values('Mike'); insert into DemoTable1(EmployeeName) values('Emma'); insert into DemoTable1(EmployeeName) values('Sam');
使用select语句显示表中的所有记录:
select *from DemoTable1;
这将产生以下输出-
+------------+--------------+ | EmployeeId | EmployeeName | +------------+--------------+ | 1 | Tom | | 2 | Mike | | 3 | Emma | | 4 | Sam | +------------+--------------+ 4 rows in set (0.00 sec)
以下是在MySQL中使用LIKE从另一个表创建新表的查询-
create table DemoTable2 LIKE DemoTable1;
让我们检查表的描述-
desc DemoTable2;
这将产生以下输出-
+--------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+----------------+ | EmployeeId | int(11) | NO | PRI | NULL | auto_increment | | EmployeeName | varchar(50) | YES | | NULL | | +--------------+-------------+------+-----+---------+----------------+ 2 rows in set (0.00 sec)