
To create a table in MySQL that matches with another table, use CREATE TABLE command with LIKE operator. The syntax is as follows −
create table yourNewTableName like yourOldTableName;
The above syntax creates structure of the table.
If you want all records then use INSERT INTO…...SELECT *FROM command. The syntax is as follows −
insert into yourNewTableName select *from yourOldTableName.
I have an old table and some data −
mysql> create table WholeWordMatchDemo −> ( −> Words varchar(200) −> ); Query OK, 0 rows affected (0.84 sec)
First, we will create a table structure. The query is as follows −
mysql> create table NewTableDuplicate Like WholeWordMatchDemo; Query OK, 0 rows affected (0.62 sec)
Now you can check the table structure has been created or not with the help of show command. The query is as follows −
mysql> show create table NewTableDuplicate;
The following is the output −
创意艺术设计的网站模板 创意艺术是指是把再简单不过的东西或想法不断延伸给予的另一种表现方式,创意设计包括工业设计、建筑设计、包装设计、平面设计、服装设计、个人创意特区等内容。 设计除了具备“初级设计”和“次设计”的因素外,还需要融入“与众不同的设计理念——创意”。搜索 一、初级设计 范围划分一般是以是否在表达图形上是否以“具象化”为指导目标,标志设计就像绘画一样真实表现图形。 二、次级设
50
+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------------------+---------------------------------------------------------------------------------------------------------------------------------------------+ | NewTableDuplicate | CREATE TABLE `newtableduplicate` (`Words` varchar(200) DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci | +-------------------+---------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
Copy all records in the new table with the name ‘NewTableDuplicate’. The query is as follows to copy all the data into new table −
mysql> insert into NewTableDuplicate select *from WholeWordMatchDemo; Query OK, 3 rows affected (0.19 sec) Records: 3 Duplicates: 0 Warnings: 0
Now you can check all records are present in the new table or not with the help of SELECT statement. The query is as follows −
mysql> select *from NewTableDuplicate;
The following is the output −
+----------------------+ | Words | +----------------------+ | My Name is John | | Carol | | My Name is Johnson | +----------------------+ 3 rows in set (0.00 sec)
Check whether the old table has the same records or not −
mysql> select *from WholeWordMatchDemo;
The following is the output −
+----------------------+ | Words | +----------------------+ | My Name is John | | Carol | | My Name is Johnson | +----------------------+ 3 rows in set (0.00 sec)
以上就是在MySQL中创建一个与另一个表匹配的表?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号