I have created a table and want to insert data into this table from another table using a join. The problem I am having is that table 2 is massive, 100s of millions of rows, so when I run my query I always get an error message "2646 no more spool space".
This is a example of the query I was trying to use, I have already created the empty column in my table.
INSERT INTO database1.table1 (empty column)
SELECT desiredcolumn
FROM database2.table2
INNER JOIN database1.table1
on table1.column = table2.column
Thanks
Try manually rinning it 10 million by 10 million splitting on ID
INSERT INTO database1.table1 (empty_column) SELECT desiredcolumn from database2.table2 INNER JOIN database1.table1 on table1.column = table2.column where table1.id <10 000 000 and table1.id > 0
then launch it several times until you did all the records
EDIT AFTER LEARNING TABLE 1 IS EMPTY - edit again:
update e_tbl
set empty_column = desiredcolumn
from database2.table2 big_tbl
INNER JOIN database1.table1 e_tbl on e_tbl.column =
big_tbl.column
where big_tbl.id <10 000 000
and big_tbl.id > 0
Try a temp table. Teradata or SQL Server?
SQL Server
SELECT desiredcolumn
into #temp
from database2.table2
INNER JOIN database1.table1
on table1.column = table2.column;
INSERT INTO database1.table1 (empty column)
SELECT desiredcolumn
from #temp;
Teradata
Create volatile Table TempTable as (
SELECT desiredcolumn
from database2.table2
INNER JOIN database1.table1
on table1.column = table2.column
) with data
on commit preserve rows;
INSERT INTO database1.table1 (empty column)
SELECT desiredcolumn
from TempTable;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.