开发者

How would I send all my data from one table to another,SQL?

开发者 https://www.devze.com 2022-12-21 05:51 出处:网络
I want to transfer th开发者_如何学Goe data from one table in sql to another is there a way to do this ? You can use standard SQL for this, specifically the insert..select statement. Say you have the f

I want to transfer th开发者_如何学Goe data from one table in sql to another is there a way to do this ?


You can use standard SQL for this, specifically the insert..select statement. Say you have the following table:

t1:
    f1 integer
    f2 varchar(50)

You can move data from that table to another similar table with:

insert into t2 (f1,f2) select f1, f2 from t1;

It doesn't have to be the same structure as long as the fields are compatible. If t2 is defined thus:

t2:
    f1 integer
    f2 varchar(7)
    f3 varchar(50)

you could do:

insert into t2 (f1,f2,f3) select f1, 'n/a', f2 from t1;

In addition. the select statement has all the regular options such as the where clause for limiting the amount of data copied, although some may not make sense (such as order by).

If you need the table itself copied (as well as copying data), select..into is the way to go:

select into t3 from t1;

This also allows a where clause which limits the data transferred.

If you need to transfer a lot of data and performance is important, you may want to consider one of the non-standard-SQL options such as unloading and reloading the table, or performance "tricks" like turning off indexing on the target table until after the data is transferred.


See this: Copying rows from other tables

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号