CREATE TABLE AS SELECT (CTAS) in MS SQL Server

In Oracle often we are using

CREATE TABLE TABLE_B AS SELECT * FROM TABLE_A;

But in SQL Server, this syntax does not work. Use

SELECT * INTO TABLE_B FROM TABLE_A;
COMMIT;

instead.

Hope this helps
Martin




You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “CREATE TABLE AS SELECT (CTAS) in MS SQL Server”

  1. HM Says:

    I have a stored procedure that combines a few tables and returns a dataset as a result. What I want to do is push that dataset into a new table. How do i do that? And can I do that before exiting the stored procedure right after my select statement?

    I can’t use your approach above, because my stored procedure set is not in a table.

    Thanks!

    HM

Leave a Reply