The COPY statement creates
a copy of an SPD Server table with or without the table indexes. In
order to use the COPY table statement, the source and target tables
must be on the same machine that the client is connected to. By default,
the software creates one or more indexes. The COPY statement is faster
than each of the following CREATE and LOAD statements:
create table ...
as select ...
create index ...
load table ...
with index...
as select ...
The COPY statement is
faster than these statements because it uses a more direct access
path than the SQL SELECT clause when it accesses the data.
You cannot use the COPY
TABLE statement if the source table and the result table have different
domain backup credentials. The source table and result table must
both be either BACKUP=yes or BACKUP=no domains. If you cannot use
the COPY statement, you must use PROC COPY to copy the tables, or
use the SQL CREATE TABLE <
tablename>
AS SELECT statement.
The following example
creates two new tables: T_NEWand T2_NEW. The first table, T_NEW, is
created with index structures identical to table T_NEW. The second
table, T2_NEW, is unindexed, regardless of the structure of table
T2_OLD.
execute(copy table t_new
from t_old)
by sasspds;
execute(copy table t2_new
from t2_old
without indexes)
by sasspds;
The COPY statement also
supports an ORDER BY clause that you can use to create a new table
with a sort order on one or more columns. COPY TABLE does not support
all of the options of PROC SORT. However, you can achieve substantial
performance gains when you create ordered tables by using the COPY
TABLE command with an ORDER BY clause when appropriate.
The next example copies
the table T_OLD to T_NEW using the order by clause. The data is ordered
by columns: x in ascending order, y in descending order, and z in
ascending order. The results are the same if you run PROC SORT on
the columns using the same BY clause. The syntax of the COPY ORDER
BY follows the typical SQL ORDER BY clause, but the column identifiers
that you can specify are restricted. You can specify only actual table
columns when you use the COPY ORDER BY clause.
execute(copy table t_new
from t_old
order by x, y desc, z asc)
by sasspds;