标签:使用 iss idt HERE .com 客户 rod innodb creat
mysql临时表在我们需要保存一些临时数据时非常有用。
临时表只在当前连接可见,当关闭连接时,mysql会自动删除表并释放所有空间。
如果使用客户端创建临时表,只有在管不客户端程序时才会销毁临时表,当然也可以手动销毁。
create TEMPORARY table `SalesSummary`(`producnt name` varchar(50) 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);
insert into SalesSummary values(‘cucumber‘,100.25,90,2);
select * from SalesSummary;
-- 删除临时表
drop table SalesSummary;
使用 show tables; 查看当前数据表时,临时表是无法看的
复制表有3种情形:
-- 1.获取数据表的完整结构
show create table csj_tbl \G;
-- 2.创建数据表
CREATE TABLE `clone_csj_tbl` (
`csj_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`csj_title` varchar(100) NOT NULL,
`csj_author` varchar(40) NOT NULL,
`submission_date` date DEFAULT NULL,
PRIMARY KEY (`csj_id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;
-- 3.复制数据
insert into clone_csj_tbl select * from csj_tbl;
select * from clone_csj_tbl;
-- 根据模版,创建新表
create table clone_csj_tbl like csj_tbl;
-- 插入数据
insert into clone_csj_tbl select * from csj_tbl;
create table clone_csj_tb1 as (select * from csj_tbl);
create table clone_csj_tbl1 as (select csj_id,csj_title from csj_tbl);
select * from clone_csj_tbl1;
更多用法:
-- 将列重命名
create table clone_csj_tbl1 as (select csj_id, csj_title as title from csj_tbl);
-- 拷贝一部分数据
create table clone_csj_tbl1 as (select csj_id,csj_title from csj_tbl where csj_id <4);
create table `clone_csj_tbl` (`id` int(3) not null auto_increment PRIMARY key) as ( select * FROM
csj_tbl where csj_id <4);
标签:使用 iss idt HERE .com 客户 rod innodb creat
原文地址:https://www.cnblogs.com/csj2018/p/9963432.html