Copying tables

Results 1 to 2 of 2

Thread: Copying tables

  1. #1
    Join Date
    Dec 1969

    Default Copying tables

    Can anyone tell me how to copy a table using a sql statement?<BR><BR>I want to copy everything (including data) and just name the tables something else.....<BR><BR>Is it possible..... Maybe something like:<BR><BR>COPY table customer new_name newcustomer ????

  2. #2
    Join Date
    Dec 1969

    Default RE: Copying tables

    EMPTY TABLE STRUCTURE v7.0 <BR>In previous SQL TechMails, we discussed how to copy data from one table <BR>into another using the INTO clause in a SELECT statement. We can <BR>further expand upon this statement to create a table structure with no <BR>data. Using an invalid WHERE clause in a SELECT INTO statement will <BR>still carry out the command but will not bring over any data into the <BR>new table. <BR><BR>SELECT * INTO TableX_Temp FROM TableX WHERE 1 = 2 <BR><BR>The above statement will copy the structure of TableX to TableX_Temp <BR>without copying any data over to TableX_Temp. Since one does not equal <BR>two, the WHERE clause portion cannot be fulfilled. However, SQL Server <BR>knows nothing about this validity at run time and therefore carries out <BR>the statement as if there is data to be moved into TableX_Temp. <BR><BR>You can also use this invalid WHERE clause to return the column names <BR>in a SELECT statement. <BR><BR>SELECT * FROM TableX WHERE 1 = 2 <BR><BR>This would return only the column headers from TableX without any data, <BR>as in the example below. <BR><BR>SSN FName LName Address <BR>---------- ---------------- --------------- ---------------------- <BR><BR>This method is much faster than using the SET FMTONLY ON/OFF option and <BR>has the advantage of being specific only to the command issued rather <BR>than the entire session. <BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts