Inserting Data with the INSERT Statement

As you know, databases aren't used only for querying data. Databases are also used for storing data. Adding data to a database is done through the use of the INSERT statement, which adds rows to a single table that you specify. For review, the following is the syntax and an explanation of the INSERT statement:

INSERT [INTO]
    {
      table_name WITH ( <table_hint_limited> [...n])
     | view_name
     | rowset_function_limited
    }
    {     [(column_list)]
        {  VALUES ( {     DEFAULT
                          |    NULL
                          |    expression
                          } [,...n]
            )
        | derived_table
        | execute_statement
        }
    }
    | DEFAULT VALUES
<table_hint_limited> ::=
    {     INDEX(index_val [,...n]) | FASTFIRSTROW | HOLDLOCK | PAGLOCK | READCOMMITTED | REPEATABLEREAD | ROWLOCK | SERIALIZABLE | TABLOCK | TABLOCKX ...

Get Writing Stored Procedures for Microsoft SQL Server now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.