Microsoft Office Tutorials and References
In Depth Information
The INSERT Statement
The insErT statement
The INSERT statement adds a new row (record) to a table. You need to specify the name of the table
where the row will be added. You may optionally omit the field names from the INSERT statement
but it is advisable that you name them anyway because it will help you to see that the values you are
entering are in the same order as the field names.
An example of using INSERT is this fictional pair of statements that respectively place the values
5432, Doe, John, Male into a table named Employees, for fields named EmployeeID, LastName,
FirstName, and Gender.
INSERT INTO EmployeeID (EmployeeID, LastName, FirstName, Gender)
VALUES (‘5432’, ‘Doe’, ‘John’, ‘Male’)
It’s standard SQL programming practice to enter the statements in upper case.
It is mandatory SQL programming practice to place the string literal VALUES
within single quotes, just as you see it here.
If you had opted to enter the preceding SQL code without naming each field, the syntax example for
that same procedure would have been as follows:
INSERT INTO EmployeeID
VALUES (‘5432’, ‘Doe’, ‘John’, ‘Male’)
The updATE statement
The UPDATE statement allows you to change the values in one or more columns (fields) in a table.
UPDATE is most commonly used to modify the value of a specific record that you identify with the
WHERE clause. You also need to specify each column you want to change, and what each column’s
new value should be.
The following example shows how you could update the contact name of one of your company’s
vendors in the ContactName column of the Vendors table. You need to be careful to specify the
WHERE clause so that only one record is changed, and that it is the correct record.
In the Vendors table, you have a field named VendorID that lists unique vendor identification
numbers. The vendor name itself is Widgets, Inc. but that is not as important as its vendor identification
number. Suppose that the vendor identification number for Widgets, Inc. is 1234. The new contact
name is John Doe, executed with these three statements in SQL:
UPDATE Vendors
SET ContactName = ‘John Doe’
WHERE VendorID = ‘1234’
 
Search JabSto ::




Custom Search