Inserting New Data

The INSERT statement is used to create new rows of data in a database. It appends a new row to a table in the database. Listing 4.5 shows the basic structure of the INSERT statement.

Listing 4.5. The Basic Structure 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
        }
    }

The following code example demonstrates how to add a new product to the Products table for Exotic Liquids using the SQL INSERT statement:

 1: INSERT INTO Products 2: ( 3: ProductName, 4: SupplierID, 5: CategoryID, 6: QuantityPerUnit, 7: UnitPrice, 8: UnitsInStock, ...

Get Programming Data-Driven Web Applications with ASP.NET 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.