We usually use the INSERT command to insert rows into the table. Sometimes, you need to add specific data to the target table based on the records of existing tables and views. This can be done using insert... select statement. The statement actually contains two parts: insert (insert statement) and select (query statement). Its syntax can be expressed as follows:
Insert into Table2 (field1, field2,...) Select value1, value2,... from Table1
In this way, a large amount of data is inserted into the target table at a time using the insert... select statement. Note the following points when using this statement:
The insert statement cannot select data from the inserted Table or view.
In the insert into statement, the number of columns must be equal to the number of columns returned from the SELECT statement.
In the insert into statement, the Data Type of the column must be the same as that of the column returned by the SELECT statement.
The syntax for the same effect in the T-SQL is as follows: Select vale1, value2 into Table2 from Table1.
Insert... select statements are usually used to create a search table, which improves the search performance. A query table can contain data distributed in multiple tables of multiple databases. Because the connection between multiple tables is slower than that of simple tayun, executing SELECT query on a table is much faster than executing a long and complex connection query.
For the outpatient doctor's site project today, you just need to copy some rows from other tables to another table and write down this article. This method is feasible and efficient, as evidenced by the following:
Of course, there are still many ways to achieve this purpose. This article provides a solution to solve this kind of requirement, which is not necessarily the best. It is only for your reference ~
If you are an expert in this field, let us know about it ~