Insert Select Strip Select to copy a table to another
Copy the statement using the SELECT INTO and INSERT into the Select table.
1.INSERT into SELECT statement
Statement form: Insert into Table2 (field1,field2,...) Select Value1,value2,... from Table1 [where column =value][] For optional content The target table Table2 must be present because the target table Table2 already exists, so we can insert constants in addition to the fields Table1 the source table. Examples are as follows:
Insert into TJJRMX (Yybh,xh,tjxmbh,jg,sfyx,zhxmbh,tjksbh,jcrq,jcys,ts,ckfw,disporder)
Select ', Xh,tjxmbh,jg,sfyx,zhxmbh,tjksbh,jcrq,jcys,ts,ckfw,disporder from tjjrmx where yybh = 5
2.SELECT into from statement
Statement form: SELECT vale1, value2 into Table2 from Table1
The target table Table2 does not exist because the table Table2 is created automatically at insert time and the specified field data in Table1 is copied to Table2. Examples are as follows:
3. from one database to another
The statement is: INSERT into the database name. Frame name-table name (column name) select (column name) from database name. frame name. Table name WHERE condition
For example: INSERT INTO MYEMP.DBO.TJDJB (YYBH)
Select Yybh from MYCMD.DBO.TJDJB where djrq= ' 2009-10-15 ' and yybh = ' 11 ' table