云服务器内容精选

  • 操作步骤 执行如下步骤对表customer_t进行深层复制。 使用CREATE TABLE语句创建表customer_t的副本customer_t_copy。 1 2 3 4 5 6 postgres=# CREATE TABLE customer_t_copy ( c_customer_sk integer, c_customer_id char(5), c_first_name char(6), c_last_name char(8) ) ; 使用INSERT INTO…SELECT语句向副本填充原始表中的数据。 1 postgres=# INSERT INTO customer_t_copy (SELECT * FROM customer_t); 删除原始表。 1 postgres=# DROP TABLE customer_t; 使用ALTER TABLE语句将副本重命名为原始表名称。 1 postgres=# ALTER TABLE customer_t_copy RENAME TO customer_t;
  • 操作步骤 使用CREATE TABLE LIKE语句创建表customer_t的副本customer_t_copy。 1 postgres=# CREATE TABLE customer_t_copy (LIKE customer_t); 使用INSERT INTO…SELECT语句向副本填充原始表中的数据。 1 postgres=# INSERT INTO customer_t_copy (SELECT * FROM customer_t); 删除原始表。 1 postgres=# DROP TABLE customer_t; 使用ALTER TABLE语句将副本重命名为原始表名称。 1 postgres=# ALTER TABLE customer_t_copy RENAME TO customer_t;
  • 操作步骤 使用CREATE TEMP TABLE AS语句创建表customer_t的临时表副本customer_t_temp。 1 openGauss=# CREATE TEMP TABLE customer_t_temp AS SELECT * FROM customer_t; 与使用永久表相比,使用临时表可以提高性能,但存在丢失数据的风险。临时表只在当前会话可见,本会话结束后将自动删除。如果数据丢失是不可接受的,请使用永久表。 临时表与普通表的存放位置无差,也可指定tablespace存放。本地临时表应用过多可能会导致系统表膨胀,但总体影响在可接受范围内。 截断当前表customer_t。 1 openGauss=# TRUNCATE customer_t; 使用INSERT INTO…SELECT语句从副本中向原始表中填充数据。 1 openGauss=# INSERT INTO customer_t (SELECT * FROM customer_t_temp); 删除临时表副本customer_t_temp。 1 openGauss=# DROP TABLE customer_t_temp;
  • 操作步骤 执行如下步骤对表customer_t进行深层复制。 使用CREATE TABLE语句创建表customer_t的副本customer_t_copy。 1 2 3 4 5 6 openGauss=# CREATE TABLE customer_t_copy ( c_customer_sk integer, c_customer_id char(5), c_first_name char(6), c_last_name char(8) ) ; 使用INSERT INTO…SELECT语句向副本填充原始表中的数据。 1 openGauss=# INSERT INTO customer_t_copy (SELECT * FROM customer_t); 删除原始表。 1 openGauss=# DROP TABLE customer_t; 使用ALTER TABLE语句将副本重命名为原始表名称。 1 openGauss=# ALTER TABLE customer_t_copy RENAME TO customer_t;
  • 操作步骤 执行如下步骤对表customer_t进行深层复制。 使用CREATE TABLE语句创建表customer_t的副本customer_t_copy。 1 2 3 4 5 6 openGauss=# CREATE TABLE customer_t_copy ( c_customer_sk integer, c_customer_id char(5), c_first_name char(6), c_last_name char(8) ) ; 使用INSERT INTO…SELECT语句向副本填充原始表中的数据。 1 openGauss=# INSERT INTO customer_t_copy (SELECT * FROM customer_t); 删除原始表。 1 openGauss=# DROP TABLE customer_t; 使用ALTER TABLE语句将副本重命名为原始表名称。 1 openGauss=# ALTER TABLE customer_t_copy RENAME TO customer_t;
  • 操作步骤 使用CREATE TEMP TABLE AS语句创建表customer_t的临时表副本customer_t_temp。 1 openGauss=# CREATE TEMP TABLE customer_t_temp AS SELECT * FROM customer_t; 与使用永久表相比,使用临时表可以提高性能,但存在丢失数据的风险。临时表只在当前会话可见,本会话结束后将自动删除。如果数据丢失是不可接受的,请使用永久表。 临时表与普通表的存放位置无差,也可指定tablespace存放。本地临时表应用过多可能会导致系统表膨胀,但总体影响在可接受范围内。 截断当前表customer_t。 1 openGauss=# TRUNCATE customer_t; 使用INSERT INTO…SELECT语句从副本中向原始表中填充数据。 1 openGauss=# INSERT INTO customer_t (SELECT * FROM customer_t_temp); 删除临时表副本customer_t_temp。 1 openGauss=# DROP TABLE customer_t_temp;