Tuesday, January 6, 2009

How to copy table in Oracle and SQL Server

Assume that you have a table tblCustomers, you want to copy this table (schema and data) to test data on it.
You can use this script:

CREATE TABLE tblCustomersCopy AS SELECT * FROM tblCustomers
Note that if you use this script in SQL Server, you can meet an error like that: Incorrect syntax near the keyword 'AS'.
To copy table in SQL Server, you can use this script:
SELECT * INTO tblCustomersCopy FROM tblCustomers

Test your new table:
Oracle:
SELECT * FROM tblCustomerCopy WHERE RowNum <>
SQL Server
SELECT TOP 10 * FROM tblCustomerCopy

DROP TABLE tblCustomersCopy

No comments:

Post a Comment