how to create structure of an exixting table without select into

  • Hi all

    i want to create structure of an exixting table without using select into.

    whether "create table table_name as select * from old_table" works in sqlserver?

  • deepikamm (3/29/2011)


    whether "create table table_name as select * from old_table" works in sqlserver?

    No. The SQL syntax is SELECT ... INTO. Why do you not want to use that?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • i need to do multipe insertions ..is it possible?

  • Explain?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • You could create the structure with

    SELECT TOP 0 * INTO <table> FROM <source>

    then perform multiple inserts int the new table

    ---------------------------------------------
    If data can screw you, it will; never assume the data are correct.

  • There is a table in our application which contains about 1 crore rows and it refers 5 tables with lakhs of rows..so we have planned to archive some of the rows from that table matching the criteria..we are undergoin a lot of data issuses so we have planned to insert the mismatch rows into another table havin the same structure as that of the problematic table.

  • Write the query that returns the mismatched rows, once you're happy it returns the correct data, add the INTO clause.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • create table structure only using

    select * into <newtable> from <oldtable> where 0 = 1

    will not create any keys, etc though only table definition

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • thank you guys..!!:)

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply