Java Reference
In-Depth Information
The INSERT Statement
The INSERT statement, in its simplest form, is used to insert data into a table, one
row or record at a time. It can also be used in combination with a SELECT statement
to perform bulk inserts of multiple selected rows from another table or tables. INSERT
can only be used to insert e ntire rows into a table, not to insert individual fields directly
into a row.
The basic form of the INSERT statement looks like this:
INSERT INTO tableName (colName1, colName2, ...) VALUES (value1, value2, ...);
To insert name and address information into the Customers Table, use an INSERT
statement like this:
INSERT INTO Customers
(First_Name, MI, Last_Name, Street,City, State, ZIP, Phone)
VALUES
('Michael','X','Corleone','123 Green','New York','NY','12345','111-222-3333');
Notice how the field names have been specified in the order in which you plan to
insert the data. You can also use a shorthand form, such as the following, if you know
the column order of the table:
INSERT INTO Customers VALUES
('Michael','X','Corleone','123 Green','New York','NY','12345','111-222-3333');
When the Customers Table is defined, the MI field is defined as NULLABLE. The
correct way to insert a NULL is like this:
INSERT INTO Contact_Info
(FName, MI, LName, Email)
VALUES
('Michael',NULL,'Corleone','offers@cosa_nostra.com');
String data is specified in quotes ('), as shown in the examples. Numeric
values are specified without quotes.
Note
There are some rules you need to follow when inserting data into a table with the
INSERT statement:
 
Column names you use must match the names defined for the column. Case is not significant.
 
Values you insert must match the data type defined for the column they are being inserted into.
 
Data size must not exceed the column width.
 
Data you insert into a column must comply with the column's data constraints.
Search WWH ::




Custom Search