Home > Articles

A Crash Course

  • Print
  • + Share This
This chapter is from the book

Adding New Data with INSERT

You can enter new data into the database by using the INSERT SQL statement. The syntax of the command is fairly simple. However, before building the query to add new data, you must know the schema of the table. Figure 3.2 shows the schema of the Categories table in the Northwind database.

Figure 3.2 The Microsoft SQL Enterprise Manager can display the schema of your database to help you build queries.

Notice that the table consists of four fields, including the CategoryID column. This field contains an integer that is automatically incremented for each new record added; we will not need to add a value with our query. Additionally, notice that the only required field in the table is CategoryName. The Description and Picture columns can both be left null. When executed, the statement in Listing 3.3 adds a new record into the category table:

INSERT INTO Categories
 'Spam and other canned-meat products'

The first line uses the keywords INSERT INTO to specify that we are inserting the data into the Categories table. Then the first parenthesized section of code specifies the fields into which we're putting our data. The VALUES keyword and the next parenthesized section enter the actual values in the same column order as the first section.

  • + Share This
  • 🔖 Save To Your Account