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

mysql 临时表和复制表

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

创建临时表

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 导出csv格式数据

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

postgresql 的安装使用

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

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

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

postgresql 查看数据库、表的大小

查看数据库的大小 select pg_database_size('test'); select pg_size_pretty(pg_database_size('test');查看单...

centos7 快速搭建 mysql

https://blog.csdn.net/qq_36582604/article/details/80526287...