当前位置:首页 > 数据库 > 正文内容

mysql 临时表和复制表

root5年前 (2022-01-18)数据库1557

创建临时表

CREATE TEMPORARY TABLE SalesSummary 
(product_name VARCHAR(50) NOT NULL, 
total_sales DECIMAL(12,2) NOT NULL DEFAULT 0.00, 
avg_unit_price DECIMAL(7,2) NOT NULL DEFAULT 0.00, 
total_units_sold INT UNSIGNED NOT NULL DEFAULT 0);

关键字 TEMPORARY 

其他跟创建正常表是一样的
临时表只在当前连接可见,那么只有在关闭客户端程序时才会销毁临时表,当然你也可以手动销毁


方法一:

show create table user;

复制结果 ,修改表名 执行就可以了
不过这里只是复制了表结构

复制数据

insert into user1(id,name,age)select id,name,age from user;


方法二:

这个方法算是上一个的简化版本

create table user2 like user ;
insert into user2 select * from user;


扫描二维码推送至手机访问。

版权声明:本文由一叶知秋发布,如需转载请注明出处。

本文链接:https://www.zhiqiu.top/?id=210

分享给朋友:

相关文章

mysql启动失败 日志InnoDB: Ignoring the redo log due to missing MLOG_CHECKPOINT between the checkpoint 3485

mysql报错Ignoring the redo log due to missing MLOG_CHECKPOINT betweenmysql版本:5.7.33系统版本:ubuntu16.04由于电脑突然关闭,跑在VMware里面的mys...

电脑断电导致mysql不可用,删除ib_logfile0和ib_logfile1恢复

mysql安装在虚拟机中,公司突然断电导致mysql启动失败查看mysql的error日志2021-05-19T06:44:51.993300Z 0 [ERROR] InnoDB: Ignoring the redo log due to...

mysql 导出csv格式数据

mysql -e "select * from newsdb.t_hk_stock_news where id <100  ...

centos7 安装mysql

centos7 安装mysql

下载rpm包wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm 安裝包仓库yum -y install * 或者yum -...

postgresql修改数据存储位置

postgresql修改数据存储位置

最近公司提供了一台新的服务器,同时有一个盘是ssd。同时为了测试postgresql的性能,将数据放置到ssd上系统centos7.9 数据库postgresql-9.6首先停掉数据库systemctl stop pos...

被Navicat坑哭的日常,版本问题

mysql5.7DROP TABLE IF EXISTS `xxx_copy1`;CREATE TABLE `xxx_copy1`  (  `id` int(11) UNSIGNED NOT NULL AUTO_INCR...