The COPY table statement
creates a copy of an SPD Server table with or without the table index(es).
For the COPY table statement to work, the source and target tables
must be on the local machine. By default, the software creates an
index(es). The COPY table statement is faster than either of the
following CREATE and LOAD statements:
create table ...
as select ...
create index ...
or
load table ...
with index...
as select ...
The COPY statement is
faster than the two above statements because it uses a more direct
access path than the SQL SELECT clause when accessing the data.
The COPY table is not
allowed if the source table and the result table have different domain
backup credentials. The source table and result table must both be
BACKUP=yes or both be BACKUP=no domains. If the COPY is not allowed,
you must use PROC COPY to copy the tables, or use the SQL CREATE TABLE
<tablename> AS SELECT statement.
In the example that
follows, two new tables are created: 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 use to create a new table with
a sort order on one or more columns of the new table. While COPY TABLE
does not support all of the options of PROC SORT, you can achieve
substantial performance gains when creating this ordered table by
using COPY 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 normal SQL ORDER BY clause, but the column identifiers
that you can specify are restricted. You can specify only actual table
columns when using the COPY ORDER BY clause.
execute(copy table t_new
from t_old
order by x, y desc, z asc)
by sasspds;