CRUD Statements  «Prev  Next»
Lesson 2 Overview of inserting data
Objective Describe how to insert data with Transact-SQL.

Inserting Data via Transact SQL

Using the INSERT statement

To insert data into a table, you use the INSERT Transact-SQL statement. With the INSERT statement you can specify the names of specific columns with which to insert data, or you can insert data into all of the table columns.
The INSERT statement uses the following general syntax:


Transact SQL - Insert Syntax

The IDENTITY column

Because SQL Server automatically generates the values for the IDENTITY column, it protects these values by not allowing insert statements that contain IDENTITY datatypes. However, if you do wish to insert values into your IDENTITY column, you can instruct SQL Server to allow this by issuing this Transact-SQL statement:

SET IDENTITY_INSERT table_name ON

Where table_name is the name of the table that contains the IDENTITY column. Remember, only one IDENTITY column can exist in a table. In the next lesson, you will get an overview of the UPDATE statement, which is used to update data in your tables.