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

mysql 临时表和复制表

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

创建临时表

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://zhiqiu.top/?id=210

分享给朋友:

相关文章

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

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

postgresql 的安装使用

安装centos系统 9.6版本# Install the repository RPMsudo yum install -y https://download.postgresql.org/pub/repos/yum/repor...

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...

清空postgresql的缓存

系统:centos,版本:postgresql-9.6因为要测试postgresql的性能,当多次查询的时候查询结果会因为缓存用时很短,不能模拟出现实使用的场景。因此需要清除缓存。首先stop掉postgresqlsystemctl sto...

mysql 重置表

truncate table 表名...