Monday 2 April 2012

SQL -Insert Statement


INSERT INTO Statement:
       
       The INSERT INTO statement is used to insert a new row in a table. This statement can be written in two forms.

Syntax for Insert data for all columns in table:

        INSERT INTO Tablename VALUES (value1,value2,……,value n);

Syntax for Insert data for particular column(s) in table:

INSERT INTO Tablename (ColumnName1,ColumnName2,……)  VALUES(value1,value2,……);

Examples:

    The table “Contact” has the columns as Id, Name, Designation, City and Mobile. We use the following Statement to insert the data for all the fields.

     INSERT INTO Contact VALUES (1,’Venkat’ ,’CEO’, ’Chennai’, 999989845);

   The Result-set is,

ID
NAME
DESIGNATION
CITY
MOBILE
1
venkat
CEO
Chennai
999989845

Note: If the datatype of column is varchar, the value enclosed with single quotes.

We use the following statement for insert the data for particular fields.

      INSERT INTO Contact (Id, Name, Designation, City) VALUES (1,’Venkat’ ,’CEO’, ’Chennai’);

The Result-set is,

ID
NAME
DESIGNATION
CITY
MOBILE
1
venkat
CEO
Chennai



No comments:

Post a Comment