1.INSERT into SELECT statement
The statement form is:
Insert into Table2 (field1,field2,...) Select Value1,value2,... from Table1 [where column =value]
[] for optional content
Requires that the target table Table2 must exist, because the target table Table2 already exists, so we can insert a constant in addition to inserting the field 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 to from statement
The statement form is: SELECT vale1, value2 into Table2 from Table1
The target table Table2 is not present because the table Table2 is automatically created when it is inserted, and the specified field data in Table1 is copied to Table2.
3. From one database to another
The statement form is: INSERT into database name. frame name. Table name (column name) select (column name) from database name. Name of the frame. Table names Where condition
Examples are as follows:
Insert into MYEMP.DBO.TJDJB (YYBH)
Select Yybh from MYCMD.DBO.TJDJB where djrq= ' 2009-10-15 ' and yybh = ' 11 '
SQL Server inserts data across libraries