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

mysql 临时表和复制表

root2年前 (2022-01-18)数据库504

创建临时表

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 重置表

truncate table 表名...

clickhouse 搭建

通过docker 部署clickhousedocker-compose文件内容如下:services:     ipwave-clickhouse:     ...

clickhouse基本数据类型

整型有符号整型Int8 - [-128 : 127]Int16 - [-32768 : 32767]Int32 - [-2147483648 : 2147483647]Int64 - [-9223372036854775808 : 9223...

mysql 导出csv格式数据

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

curl 访问es 常用的命令

查询有哪些索引curl -X GET 'http://10.0.0.143:8200/_cat/indices'查询索引的别名curl  -XGET 'http://127.0.0.1:8200/index...

清空postgresql的缓存

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