
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create a temporary table similar to a regular table with MySQL LIKE
Let us first create a table −
mysql> create table DemoTable1 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(100) ); Query OK, 0 rows affected (0.59 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1(Name) values('Chris'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1(Name) values('Robert'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1(Name) values('Mike'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1(Name) values('Sam'); Query OK, 1 row affected (0.07 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable1;
This will produce the following output −
+----+--------+ | Id | Name | +----+--------+ | 1 | Chris | | 2 | Robert | | 3 | Mike | | 4 | Sam | +----+--------+ 4 rows in set (0.00 sec)
Following is the query to create a temporary table LIKE a regular table −
mysql> create temporary table DemoTable2 like DemoTable1; Query OK, 0 rows affected (0.04 sec)
Let us check the description of the table −
mysql> desc DemoTable2;
This will produce the following output −
+-------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+----------------+ | Id | int(11) | NO | PRI | NULL | auto_increment | | Name | varchar(100) | YES | | NULL | NULL | +-------+--------------+------+-----+---------+----------------+ 2 rows in set (0.04 sec)
- Related Questions & Answers
- Create a temporary table with dates in MySQL
- Create a temporary table in a MySQL procedure?
- How to create a temporary MySQL table in a SELECT statement without a separate CREATE TABLE?
- How to create a new table from the first table using MySQL LIKE?
- How to create a MySQL table with InnoDB engine table?
- How to create a MySQL table with MyISAM engine table?
- Insert multiple values in a temporary table with a single MySQL query?
- How can we create a MySQL temporary table by using PHP script?
- How to create a MySQL table with indexes?
- Create a new table with the properties of an old table and without duplicates using MySQL LIKE Operator?
- Create MySQL query to create a table from an existing table?
- Setting similar value for a column in a MySQL table?
- Create a dynamic table name from current year in MySQL like 2019
- How to list temporary table columns in MySQL?
- How can I delete MySQL temporary table?
Advertisements