Inserting Data

THE INSERT STATEMENT

•    The INSERT INTO statement is used to insert new records in a table.

INSERT INTO statement in two ways:

1.    Specify both the column names and the values to be inserted.

 

          INSERT INTO table_name (column1, column2, column3, . . . )

          VALUES (value1, value2, value, . . . );

 

2.    If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query. However, make sure the order of the values is in the same order as the columns in the table.

 

           INSERT INTO table_name

          VALUES (value1, value2, value, . . . );

 

EXAMPLE:

 

            INSERT INTO CUSTOMER (CustomerID, FirstName, LastName,

               Street, City, State, Zipcode, Phone)

              VALUES ( :vcustid, 'David', 'Taylor', '235 Loco Ave. ' ,

               'El Pollo', 'CA', '92683', '(617) 555-1963') ;

 

•    The INSERT statement works equally well whether you use variables or an explicit copy of the data itself to form the arguments of the VALUES keyword.

 

Retrieving data with SELECT

THE SELECT STATEMENT.

•    The SELECT statement is used to select data from a database.

 

               SELECT column1, column2, . . . 

               FROM table_name;

 

EXAMPLE:

 

               SELECT CustomerName, City FROM Customers;