| Start |
|---|
| INSERT multiple rows of data To insert multiple rows of data in SQL Server 2008 or later: To insert multiple rows of data in earlier versions of SQL Server, use "UNION ALL" like so: Note, the "INTO" keyword is optional in INSERT queries. Another warning is that SQL server only supports 1000 rows in one INSERT so you have to split them in batches. |
| Use OUTPUT to get the new Id When INSERTing, you can use When programatically calling this (e.g., from ADO.net) you would treat it as a normal query and read the values as if you would've made a If the ID of the recently added row is required inside the same set of query or stored procedure. |
| INSERT from SELECT Query Results To insert data retrieved from SQL query (single or multiple rows) Note, 'student' in SELECT is a string constant that will be inserted in each row. If required, you can select and insert data from/into the same table |
| INSERT a single row of data A single row of data can be inserted in two ways: Or Note that the second insert statement only allows the values in exactly the same order as the table columns whereas in the first insert, the order of the values can be changed like: |
| INSERT on specific columns To do an insert on specific columns (as opposed to all of them) you must specify the columns you want to update. This will only work if the columns that you did not list are nullable, identity, timestamp data type or computed columns; or columns that have a default value constraint. Therefore, if any of them are non-nullable, non-identity, non-timestamp, non-computed, non-default valued columns...then attempting this kind of insert will trigger an error message telling you that you have to provide a value for the applicable field(s). |
INSERT Hello World INTO table |
Read Article
https://develop.horje.com/learn/1434/reference