我们可以通过多少种方式在 sql 服务器中插入记录
In how many ways we can insert records in sql server
就像一次插入一条或多条记录一样,一个 table 数据插入到另一个 table 的列数有限。
- 批量插入
https://docs.microsoft.com/en-us/sql/t-sql/statements/bulk-insert-transact-sql
- 插入交易
https://docs.microsoft.com/en-us/sql/t-sql/statements/insert-transact-sql
- Select插入
https://www.w3schools.com/sql/sql_insert_into_select.asp
希望这会有所帮助
有(至少)四种方式:
INSERT
。很明显。它支持作为文字值提供的单行和多行,以及插入查询或存储过程的结果。
SELECT .. INTO
将查询结果插入到新的 table.
BULK INSERT
. Bulk inserts data from files. It's a little quirky and not very flexible when it comes to parsing files, but if you can get the data to line up it works well enough. Selecting data for bulk insert purposes can also be done with OPENROWSET(BULK, ...)
.
INSERT BULK
. This is an internal command that's used under the covers by drivers that use the bulk insert protocol in TDS (the protocol used by SQL Server). You do not issue these commands yourself. Unlike BULK INSERT
, this is for client-side initiated bulk inserting, for example through the SqlBulkCopy
class in .NET, or SQL Server's own bcp
工具.
所有其他插入数据的接口和方法都在幕后使用这些方法之一。其中大部分将使用普通的旧 INSERT
.
就像一次插入一条或多条记录一样,一个 table 数据插入到另一个 table 的列数有限。
- 批量插入 https://docs.microsoft.com/en-us/sql/t-sql/statements/bulk-insert-transact-sql
- 插入交易 https://docs.microsoft.com/en-us/sql/t-sql/statements/insert-transact-sql
- Select插入 https://www.w3schools.com/sql/sql_insert_into_select.asp
希望这会有所帮助
有(至少)四种方式:
INSERT
。很明显。它支持作为文字值提供的单行和多行,以及插入查询或存储过程的结果。SELECT .. INTO
将查询结果插入到新的 table.BULK INSERT
. Bulk inserts data from files. It's a little quirky and not very flexible when it comes to parsing files, but if you can get the data to line up it works well enough. Selecting data for bulk insert purposes can also be done withOPENROWSET(BULK, ...)
.INSERT BULK
. This is an internal command that's used under the covers by drivers that use the bulk insert protocol in TDS (the protocol used by SQL Server). You do not issue these commands yourself. UnlikeBULK INSERT
, this is for client-side initiated bulk inserting, for example through theSqlBulkCopy
class in .NET, or SQL Server's ownbcp
工具.
所有其他插入数据的接口和方法都在幕后使用这些方法之一。其中大部分将使用普通的旧 INSERT
.