intoUsing INSERT INTO to Add Records to MSSQL Databases(mssqlinsert)

SQL is a powerful and popular data manipulation language used to add, update and delete records in MSSQL databases. One way to add records using SQL is by using the ‘INSERT INTO’ statement. The INSERT INTO statement is used to indicate that a new record is to be inserted into a particular table in the database. It is made up of a few parts, the names of the table and the columns to insert into, and the data to be inserted into each column.

Take the following project database table for example:

| id | name | status |

|—–|——-|———-|

| 1 | Quail | Merging |

| 2 | Crow | Editing |

| 3 | Owl | Released |

If we wanted to add a new bird, we could use the following statement to add a record for the Duck to the table:

`INSERT INTO project (id, name, status) VALUES (4, ‘Duck’, ‘Draft’);`

This statement will add a new row to the table with a containing the values ‘4’ for id, ‘Duck’ for name, and ‘Draft’ for status.

We can also use multiple values when inserting with the INSERT INTO statement. Consider if we wanted to add two new birds at the same time:

`INSERT INTO project (id, name, status) VALUES (5, ‘Hawk’, ‘Pending’), (6, ‘Eagle’, ‘Approved’);`

The statement above consists of two insertions separated by a comma. The first insertion adds a row for a Hawk, with the values ‘5’ for id, ‘Hawk’ for name, and ‘Pending’ for status. The second insertion adds a row for an Eagle, with the values ‘6’ for id, ‘Eagle’ for name, and ‘Approved’ for status.

Using INSERT INTO we can quickly add records to an MSSQL database table. It is a powerful tool and can be used to add single or multiple records in one statement. It is important to ensure that the values specified match the correct column types in the table otherwise an error will be raised.


数据运维技术 » intoUsing INSERT INTO to Add Records to MSSQL Databases(mssqlinsert)