Using Select Into

Hello,

I am trying to use the following statement,

ALTER TABLE AuditAbatements ADD SELECT * INTO AuditAbatements FROM Abatements WHERE 1 = 2, but I am getting a syntax error.

I am trying to copy the structure of another table into a table that is already created. Can this be done

Thanks



Answer this question

Using Select Into

  • Goofs

    Sorry, forgot to add:

    And to do this dynamically you would have to create a dynamic SQL statement, built up from the table definition. Not advisable.


  • AxeldraX

    Not as far as I am aware, no. Why not just drop the table and then re-create it Select INTO is used to copy data into a table, not copy a schema over an existing schema. If you want to dynamically copy the schema of one table into another (i.e. you don't know what table to want to copy the schema of until runtime) then you should use the system tables and system views. But I would not advise that.
  • Pierce Blaylock

    Thanks for your help!
  • John-at-WSRB

    Please mark the post as answered if that answered your question, otherwise people will keep checking it to post answer, and then find it answered.
  • Using Select Into